Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

What about the next statement afeter response.redirect and     server.transfer?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lander - 10 Mar 2008 04:20 GMT
I've seen many people have written code like this:

response.redirect();
return;

or

server.transfer();
return;

I doubt whether the statement "return;" will be hit? I think it's
redundant, isn't it?
Mark Rae [MVP] - 10 Mar 2008 07:47 GMT
> I doubt whether the statement "return;" will be hit? I think it's
> redundant, isn't it?

No.

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

George Ter-Saakov - 10 Mar 2008 14:35 GMT
You right.
return will never bit hit in this case.

But I still always put it for clarity

George.

> I've seen many people have written code like this:
>
[quoted text clipped - 8 lines]
> I doubt whether the statement "return;" will be hit? I think it's
> redundant, isn't it?
Mark Rae [MVP] - 10 Mar 2008 14:55 GMT
>> I've seen many people have written code like this:
>>
[quoted text clipped - 11 lines]
> You are right.
> return will never bit hit in this case.

That's incorrect...

protected void Page_Load(object sender, EventArgs e)
{
   if (this == that)
   {
       Response.Redirect("mypage.aspx", false);
       //return;
   }

   if (this != that)
   {
       // this *will* run if the above return is not unremmed...
   }
}

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

George Ter-Saakov - 10 Mar 2008 16:02 GMT
Yes, there is a second parameter which will change default behavior.

But default behavior would terminate the execution.

So in
Response.Redirect("mynewpage.aspx")
return;

"return" is unnecessary

George.

>>> I've seen many people have written code like this:
>>>
[quoted text clipped - 27 lines]
>    }
> }
Mark Rae [MVP] - 10 Mar 2008 16:19 GMT
>>> You are right.
>>> return will never bit hit in this case.
[quoted text clipped - 18 lines]
>
> But default behavior would terminate the execution.

Yes, that's true, but that would raise a
System.Threading.ThreadAbortException...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

bruce barker - 10 Mar 2008 19:15 GMT
thats generally what you want.

overwise you need to override the render event, set a flag that a redirect
was done, then cancel the render (and maybe prerender). you may need to also
override the event firing logic, as you probably don't want to raise events
after a redirect.

if you don't do this, all the page processing happens, and html is
downloaded to the browser, but ignored because of the redirect header.

-- bruce (sqlwork.com)

> >>> You are right.
> >>> return will never bit hit in this case.
[quoted text clipped - 21 lines]
> Yes, that's true, but that would raise a
> System.Threading.ThreadAbortException...
lander - 13 Mar 2008 08:21 GMT
> >>> You are right.
> >>> return will never bit hit in this case.
[quoted text clipped - 27 lines]
>
> - 显示引用的文字 -

Hi mark, would you pls explain *why* to us? Thanks really.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.