QA


Q&A

Q1:

Sometimes when I refresh my browser on a web page with a form, I receive the message "This page cannot be refreshed without resending the form information" or "The page contains POSTDATA. Do you want to refresh?" What does this mean?

A1:

Recall that there are two ways an HTML form can submit its values: through the querystring or through the HTTP Post headers. When a postback form is used, the HTML form uses the HTTP Post headers and submits the form to the same URL. (Refer to Figure 9.4 for more on postback forms.)

When you ask your browser to refresh the web page after you have submitted a postback form, the browser doesn't know whether you want to repost the web page resubmitting the HTTP Post headers. Therefore, it asks if you want to resend the form information.

You may also notice this behavior when clicking the Back button to return to a page that has been requested via a postback.

Q2:

Why do ASP.NET Web Forms use postback? Why not direct the user to another page or pass the information along in the querystring?

A2:

ASP.NET Web Forms use postback forms over alternative methods for a number of reasons. The most important being that postback forms allow the ASP.NET Web controls to maintain their state across postbacks. Recall that when a user enters a value into a TextBox Web control and submits the form, the ASP.NET page is posted back and the TextBox Web control's Text property is updated to the value the user entered. For the TextBox Web control's Text property to be updated with the value the user entered, the Web Form must submit back to the same page that contains the TextBox Web control. (A lengthy discussion on why this is the case is far beyond the scope of this book.)

Additionally, the HTTP Post headers are used as opposed to the QueryString because often a large amount of data is being passed back in the Post headers. Some older browsers have a limit on the amount of information that can be passed through the querystring. Furthermore, it would be unsightly to have such a mangled querystring.




Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net