Skip to Content
Beginning ASP.NET 3.5: In C# and VB
book

Beginning ASP.NET 3.5: In C# and VB

by Imar Spaanjaars
March 2008
Intermediate to advanced content levelIntermediate to advanced
766 pages
21h 15m
English
Wrox
Content preview from Beginning ASP.NET 3.5: In C# and VB

7.3. Programmatic Redirection

Programmatic redirection is very useful and common in ASP.NET pages. For example, imagine a page that allows users to enter a review into the database. As soon as they click the Save button, the review is saved and then users are taken to another page where they can see the entire review.

ASP.NET supports two major ways to redirect users to a new page programmatically: using Response.Redirect and Server.Transfer. Since both behave pretty differently, the following two sections describe their behavior in more detail.

7.3.1. Programmatically Redirecting the Client to a Different Page

Within each ASPX page you have access to a property called Response that you saw earlier when saving the cookie for the selected theme. The Response object gives you access to useful properties and methods that are all related to the response from the server to the user's browser. One of those methods is the Redirect method. This method sends an instruction to the browser to request a new page. This is useful if you want to redirect your user to another page in your site, or to a completely different web site. The Redirect method can be used in two different ways:

Response.Redirect(newUrl)
Response.Redirect(newUrl, endResponse)

The second version, which has an additional Boolean parameter called endResponse, allows you to execute any remaining code after the call to Response.Redirect when you pass False for the endResponse parameter. This is usually not necessary so you're ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning ASP.NET 4: in C# and VB

Beginning ASP.NET 4: in C# and VB

Imar Spaanjaars
Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader

Publisher Resources

ISBN: 9780470187593Purchase book