What is the sequence of events triggered in an asp.net gridview control?

I use GridViews quite often, and sometimes I get confused with where to put certain code. What is the sequence in which events occur, including all events on the page?

Edited: I am also trying to understand what is happening between the page and the Gridview. Do events ever happen? Or do all the events on the page happen right after all the Gridview events? And not only GridViews, any control, but most often GridView.

+6
events gridview sequence
source share
4 answers
protected void GridView1_Load(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("GridView1_Load"); } protected void GridView1_DataBinding(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("GridView1_DataBinding"); } protected void GridView1_DataBound(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("GridView1_DataBound"); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { System.Diagnostics.Debug.WriteLine("GridView1_RowDataBound"); } 
+3
source share

If you link to the page life cycle, you can find an overview here .

Life Cycle Summary:

Page request

A page request occurs before the start of the page life cycle. When a page is requested by the user, ASP.NET determines whether the page should be parsed and compiled (therefore, the page will begin to serve), or whether it is possible to send a cached version of the page in response without starting the page.

Start

Initially, page properties are set, such as request and response. At this point, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. In addition, the UICulture property of the page is initially set.

Page initialization

During page initialization, the controls on the page are available and each UniqueID control is installed. Any themes also apply to the page. If the current request is postback, postback data has not yet been loaded, and control property values ​​have not been restored to values ​​from the view state.

Load

At boot time, if the current request is reverse processing, control properties are loaded with information recovered from the view state and control state.

Validation

During validation, the Validate method of all validation controls is called, which sets the IsValid property for individual validation elements and the page.

Handling Inverse Events

If the request is a postback, all event handlers are called.

Rendering

Before rendering, the view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text script that writes its output to the Response property's OutputStream.

Unload

Unloading is called after the page has been fully displayed, sent to the client and ready to be discarded. At this point, page properties, such as Response and Request, are unloaded and any cleanup is performed.

As for the GridView events, they can be found here .

+7
source share
+2
source share

There's a longer list in ASP.NET 2.0 Event Ordering (note that this is for 2.0).

0
source share

All Articles