Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the sequence of events firing off in asp.net Gridview control?

I use GridViews pretty often and sometimes I get confused to where to put certain code. What is the sequence that events are fired off including all page events?

Edited: I really am also trying to understand what happens between the page and the Gridview. Do the events ever cross? Or do all page events occur at once then all Gridview events occur? And not just GridViews, any control - but mostly page and GridView interaction.

like image 707
Eric Avatar asked Jun 05 '09 19:06

Eric


People also ask

What is the sequence in which ASP.NET events are processed?

When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering.

What is the sequence of event firing during page load of?

The page Load event occurs first followed by the Load event for all controls (recursively). This is where most coding is done, so you want to check the IsPostBack property to avoid unnecessary work. LoadComplete: This event is fired when the page is completely loaded.

What is the first event that gets fired during ASP.NET page load?

Init for every control on the Web Form The first stage in the page life cycle is initialization. After the page's control tree is populated with all the statically declared controls in the . aspx source the Init event is fired.

What is the flow of page events in ASP.NET page?

The Asp.net page life cycle includes the events preinit, Init, InitComplete, OnPreLoad, Load, LoadComplete, OnPreRender, and OnSaveStateComplete. These events take place whenever an ASP.NET page is requested.


2 Answers

If you're refering to the Page Life Cycle, you can find an overview here.

Summary of the life cycle is:

Page request

The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.

Start

In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.

Page initialization

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

Load

During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.

Validation

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

Postback event handling

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

Rendering

Before rendering, 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 writer that writes its output to the OutputStream of the page's Response property.

Unload

Unload is called after the page has been fully rendered, sent to the client, and is 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.

like image 124
Joseph Avatar answered Nov 15 '22 02:11

Joseph


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");
}
like image 36
Ropstah Avatar answered Nov 15 '22 00:11

Ropstah