Unlike forms in desktop applications, an ASP.NET Web page does not start up, run while the user works with the form, and then unload only when the user clicks a Close button. This is because the Web is inherently disconnected. When a browser requests a page from a Web server, the browser and the server are connected only long enough to process the request. After the Web server has rendered a page to the browser, the connection is terminated. If the browser makes another request to the same Web server, even for the same page, this request is processed as a new request.
The disconnected nature of the Web dictates the way an ASP.NET page runs. When a user requests an ASP.NET Web page, a new instance of the page is created. The page performs its processing, renders markup to the browser, and is then discarded. If the user clicks a button to perform a postback, a new instance of the page is created, the page performs its processing, and is again discarded. Thus, each postback and round trip results in a new instance of the page.
For more information, see Creating ASP.NET Web Pages.
Preserving Page State
In normal HTTP protocol, the only information that the server has about a page is the information that the user has specified using controls on the page, because the browser sends only that information to the server when the page is posted. Other information, such as variable values and property settings, is discarded. ASP.NET helps preserve other page information in the following ways:
ASP.NET saves control settings (properties) between round trips, which is called saving control state.
ASP.NET provides state management capabilities so you can save your own variables and application-specific or session-specific information between round trips.
ASP.NET can detect when a page is requested for the first time and when the page is posted, which allows you to program accordingly. For instance, you might want to read information from a database the first time a page is displayed, but not on every postback.
Note: |
|---|
The server can be configured to cache page information to optimize the pages, but for purposes of application programming, it is clearest to think of pages as being disposed of as soon as the server has finished processing them.
|
For more information, see ASP.NET State Management Overview.