-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: bhavesh26
Message 1 in Discussion
Hi All, All the ASP.Net web developers use Redirect() method of the
Response Object frequently.Method is looks like 1. Response.Redirect(Url as
string) 2. Response.Redirect(Url as String,endResponse as boolean) We
usually not provide second args.Now let's examine following code segments:
Dim strName As String = "Bhavesh"
Try
If strName.Equals("Bhavesh") Then
Response.Redirect("page1.aspx)
Else
Response.Redirect("page2.aspx")
End If
Catch ex As Exception
Response.Redirect("CommonError.aspx")
End Try
Now what do you expect,Where control will go? You might say (as me,seeing
vey first time) it will go to page1 or page2 depending on the condition.But the
fact is that it will go commonError.aspx page,why so ? just think for some time
if you still cann't find the reason read the reason stated in next few lines.
Reason :- Response.Redirect method stops the current executing thread and
redirect the server to the new page. If this are put under try-catch block, it
raises the exception(System.Threading.ThreadAbortException) as the current
execution thread is broken, and thus it will always redirect to the
CommonError.aspx page. We must provide the second args in the redirect method
as False to redirect as per the condition.Default value is True.So the code
should looks like this response.redirect(page*,False) cheers, Bhavesh
Patel, Jr. Software Engg, Elegant Microweb Pvt. Ltd, Ahmedabad.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]