100 likes | 226 Views
Explore various methods for server-side page redirection in ASP.NET, including using the PostBackUrl property, Cross-Page Posting, and retrieving request data. Learn how to set a default start page, work with the PreviousPage object, and handle data extraction during the Page_Load event. Delve into alternative redirection methods such as Server.Transfer and Response.Redirect, and understand how to pass data using URL parameters. Additionally, discover how to manage unhandled errors with custom pages through the web.config file for a robust web application.
E N D
CSCI 6962: Server-side Design and Programming Page Redirection
Redirecting to Other Pages • PostBackUrlproperty • Used to set the page that ASP will load upon request • Can then access request data from previous page
Setting Start Page • Can set default start page • Right-click page and select “Set as Start Page”
Cross-Page Posting • PostBackUrl is property of each dynamic component • If component activated, transfer to this page instead of posting back to previous page
Retrieving Request Data • PreviousPage object contains reference to form on previous page • Can use PreviousPageIsNot Nothing to make sure it exists • PreviousPage.FindControl(“id”) • Returns reference to previous page element with that id • Usually have to cast to actual type with CType(element, type) • Note: behavior can be flaky, particularly if components inside other containers or forms
Retrieving Request Data • Usually done in Page_Load method in response page • Called when page first loaded Get controls from previous page Extract data from those controls CInt converts string to integer
Other Redirection Methods • Server.Transfer(“URL”) • Server-side redirection • Response.Redirect(“URL”) • Client-side redirection (extra round trip to server) • Invoked programically within event handling code • Do not (easily) pass information from previous form • Often used with sessions
Passing Data Using the URL • Can manually add data to the URL string itself in form URL?name=value&name=value...
Passing Data Using the URL • Can extract the parameters usingRequest.QueryString(“name”)
Unhandled Errors • As with JSP, can specify default pages for unhandled errors • Done in web.configfile • Inside CustomErrorstag • Specify page to go to for unhandled problems with defaultRedirect • Can specify pages for specific types of problems with errorsubtag, specifying statusCode • 404 = Missing page • 500 = Unhandled exception