Web page processing

When you design a Web page, you need to code specific processing in events that are fired when the page is processed.

Page initialization

When a page is rendered, its Page_Init event is triggered. The ASP.NET framework restores the ViewState of the page and its controls and restores data that has been posted back.

Page loading

In the Page_Load event, you can perform initial data binding if the Page.IsPostBack property is false, or, if it is true, you can read and restore values and update control properties.

Validation and event handling

After these events have fired, the Validate method of validator Web server controls, if any are associated with the page, is invoked before application-specific events are handled. If any control events have been cached, as specified by the AutoPostBack property, they are processed before the event that caused the page to be posted. Your application-specific events should check the IsValid property for page and validation controls, save the state of page variables that you are maintaining, and save the state of controls that have been added to the page dynamically.

Page unloading

When the page has finished rendering and is ready to be discarded, the Page_Unload event fires. You should perform final cleanup work in this event, such as closing database connections and discarding objects.