views:

25

answers:

1

a) In Asp.Net we can check whether a request is a postback or not via Page.IsPostBack property.But where does this property get its value from? Thus, where in the incoming request does browser put this value?

b) As far as I can tell, hitting a reload button also causes browser to send form data back to the server. Thus, is under the hood hitting browser’s reload button same as pressing a submit button ( which is nested within a FORM element)?

c) Assuming browser displays A.aspx for the fist time and assuming user clicks browser’s reload button, then I would think this request will be considered as a postback by Asp.Net (especially since browser also sends back any form data), but it’s not. Why?

thanx

+3  A: 

The IsPostBack property only looks to see if the request made is a POST request action. If it is a POST, then IsPostBack returns true.

Hitting reload / refresh on a browser does NOT in general send any form data to the server - most of the time this causes a GET request (which is the default request you send any time you first visit a site).

If you click refresh on a page that was received as a result of a POST operation, then the browser will ask the user if they would like to submit the data again before doing the POST request again. A browser will not resubmit any form data unless the user confirms it (at least that is how it works in the IE, Firefox and Chrome).

Fiddler is a great tool to help with this kind of situation. It sits in the middle between the browser and the server and you can watch all of the traffic go back and forth. You can download it here.

davisoa
1 - "The IsPostBack property only looks to see if the request made is a POST request action. If it is a POST, then IsPostBack returns true." So there's no way for first request to be POST request? 2 - "Hitting reload / refresh on a browser does NOT in general send any form data to the server" If A.aspx contains a TextBox control and if on first page load user enters some text into textbox and clicks browser's reload button, then when page reloads, text user entered is still there. If form data wasn't sent to the server, then why did browser display text on reload?
flockofcode
The first request of a page should by definition not be a POST request, since a POST is supposed to send data entered by the user. I think your second question is due to the browser helping the user by auto entering the text they entered into the text box upon the reload.You can see exactly what is happening with Fiddler. I'll amend my answer to include a link to this amazing tool.
davisoa
thank you for your help
flockofcode