Handling Re-entrant Pages

You might have noticed some code in the DataTest1_Load event handler. That code was

If Not IsPostback Then   ' Evals true first time browser hits the page

The IsPostback check is used to determine whether the user has called this form before. Think about the stateless nature of HTTP: Any time someone calls a form, it looks like a brand-new user to the Web server. ASP.NET, however, writes some ViewState information into the page when it is rendered and sent to the client. That way, when the client submits the page back to the server, ASP.NET can see that the page has been sent back to the user before. Therefore, the code inside this If statement runs only once for each user who requests this page. This can be important. For example, if you want to know which users visit which pages, you can record that information just once instead of each time that an event is passed back to the server.

ASP.NET server controls work on a re-entrant page model. In other words, when a control's events cause the form in the page to be submitted, the page calls itself. In an HTML sense, the Action attribute in the <Form> tag points to the same page you are already viewing. This means that many forms call themselves over and over, and the IsPostback is important to improve the scalability and performance of the application.

Therefore, unlike a Windows application, the Load and Unload events can fire many times while using the same page. IsPostback provides an easy way to see whether this is truly the first load for a particular user.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.13.179