Stop processing after a error message in ASP.NET 2.0

116 views
Skip to first unread message

abhinandan

unread,
Aug 29, 2008, 1:13:16 AM8/29/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting, abhina...@rasstechnologies.com
Hello All,
I have 2 textbox,consider txtbox1 and txtbox2.I have 2 buttons
next to these textboxes,Consider btn1 and btn2.

[ txtbox1 ] ( btn1 )

[ txtbox2 ] ( btn2 )


When i click btn2 it will check if ttbox1 is empty or not and will
display a error message(alert) else will process.

i want to stop the processing after the alert message is displayed.how
do i do it?


protected void btn2_click( sender , e)
{
if( txtbox1 == "")
{
scriptmanager.RegisterStartupScript(this.page,typeof(String),"error","alert('textbox
should not be empty');",true);

/// I want to stop the processing here.I tried Response.End(),Break,
didnt work.Any solution?

}
else
{
/// processes the code here
}


}



Regards,
S.S.Abhinandan

Monty

unread,
Aug 29, 2008, 2:54:49 AM8/29/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
shouldn't this
if( txtbox1 == "")
be
if( txtbox1.text == "") ?

Regards
Monty

Cerebrus

unread,
Aug 29, 2008, 4:30:54 AM8/29/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
The problem is that your basic premise is wrong. It is wrong because
your understanding of the ASP.NET page lifecycle is amiss. I say your
understanding is amiss because you need to understand that ASP.NET
code executes on the server and the HTML output is sent to the client
browser. Alerts are javascript functions that are executed by the
browser solely on the client. When you use the RegisterStartupScript
method, it just tells ASP.NET to include that script segment in the
HTML that it is going to send to the client. Since the server does not
execute the "alert", you cannot terminate execution immediately after
the alert is displayed, because your subsequent code has already been
executed.

On Aug 29, 10:13 am, abhinandan <abhinanda...@gmail.com> wrote:
> Hello All,
>       I have 2 textbox,consider txtbox1 and txtbox2.I have 2 buttons
> next to these textboxes,Consider btn1 and btn2.
>
> [     txtbox1        ]    (   btn1  )
>
> [     txtbox2        ]    (   btn2  )
>
> When i click btn2 it will check if ttbox1 is empty or not and will
> display a error message(alert) else will process.
>
> i want to stop the processing after the alert message is displayed.how
> do i do it?
>
> protected void btn2_click( sender , e)
> {
> if( txtbox1 == "")
> {
> scriptmanager.RegisterStartupScript(this.page,typeof(String),"error","alert­('textbox

abhinandan

unread,
Aug 29, 2008, 7:01:03 AM8/29/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
ya its txtbox1.text, i thought its understood ;-)

@cerebrus
thanks for the information.probably i need to take care of these
things and know them clearly.Anyways what else can i do to stop the
processing? Is there a way to do it in my senario?
> > S.S.Abhinandan- Hide quoted text -
>
> - Show quoted text -

Glenn

unread,
Aug 29, 2008, 7:04:46 AM8/29/08
to DotNetDe...@googlegroups.com
"return"   ??????
 
...Glenn

Jakub Malinowski

unread,
Aug 29, 2008, 3:29:39 PM8/29/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Use ClientClick event and write code in js

Sitab Bhandari

unread,
Sep 10, 2008, 8:25:15 AM9/10/08
to DotNetDe...@googlegroups.com
use return;

But use javascript on aspx page not on server side form for button click event...........

Reply all
Reply to author
Forward
0 new messages