Copy Code code as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
public partial class _default:page
{
protected void Page_Load (object sender, EventArgs e)
{
}
#region Onpreinit First Step
protected override void Onpreinit (EventArgs e)
{
Check the IsPostBack property to determine if the page is being processed for the first time.
Create or recreate a dynamic control.
Dynamically set the master page.
Dynamically set the Theme property.
Reads or sets the profile property value.
Attention
If the request is a postback, the value of the control has not been restored from view state. If you set control properties at this stage, their values may be overridden in the next event.
Base. Onpreinit (e);
}
#endregion
#region OnInit Second Step
protected override void OnInit (EventArgs e)
{
Raised after all controls have been initialized and all skin settings have been applied. Use this event to read or initialize the properties of a control.
Base. OnInit (e);
}
#endregion
#region Oninitcomplete Third Step
protected override void Oninitcomplete (EventArgs e)
{
Raised by the Page object. Use this event to handle tasks that require you to complete all initialization work first.
Base. Oninitcomplete (e);
}
#endregion
#region Preload Fourth Step
protected override void Onpreload (EventArgs e)
{
Use this event if you need to perform processing on the page or control before the Load event.
After the Page raises the event, it loads view state for itself and all controls, and then handles any postback data that is included with the Request instance.
Base. Onpreload (e);
}
#endregion
#region OnLoad Fifth Step
protected override void OnLoad (EventArgs e)
{
Page increases the OnLoad event method on page and then recursively performs the same operation on each child control, so that it repeats until the page and all the controls are loaded.
Use the OnLoad event method to set properties in the control and establish a database connection.
Base. OnLoad (e);
}
#endregion
Sixth Step #region Control event
protected void Button1_Click (object sender, EventArgs e)
{
Use these events to handle specific control events, such as the Click event of a Button control or the TextChanged event of a TextBox control.
Attention
In a postback request, if the page contains a validator control, check the IsValid properties of the page and each validation control before performing any processing.
}
#endregion
#region Onloadcomplete Seventh Step
protected override void Onloadcomplete (EventArgs e)
{
Use this event for tasks that need to load all other controls on the page.
Base. Onloadcomplete (e);
}
#endregion
#region OnPreRender Eighth Step
protected override void OnPreRender (EventArgs e)
{
Before this event occurs:
The Page object invokes ensurechildcontrols for each control and page.
Each data-bound control that has the DataSourceID property set invokes the DataBind method. For more information, see Data-binding events for data-bound controls below.
PreRender events occur for each control on the page. Use this event to make a final change to the contents of a page or its controls.
Base. OnPreRender (e);
}
#endregion
#region Savestatecomplete nineth Step
protected override void Onsavestatecomplete (EventArgs e)
{
ViewState was saved for the page and for all controls before the event occurred. Any changes made to the page or control at this time will be ignored.
Use this event to perform a task that requires that view state has been saved, but that no changes have been made to the control.
Base. Onsavestatecomplete (e);
}
#endregion
#region Render Tenth Step
Render
This is not an event; At this stage of processing, the Page object will be raised with this method on each control. All asp.net Web server controls have a Render method for writing a control tag that is set to be sent to the browser.
If you create a custom control, you typically override this method to output the markup for the control. However, if your custom control merges only standard asp.net Web server controls and does not incorporate custom tags, you do not need to override the Render method. For more information, see Developing custom ASP.net server controls.
The user control (. ascx file) automatically merges the rendering, so you do not need to render the control explicitly in your code.
#endregion
#region OnUnload 11th Step
protected override void OnUnload (EventArgs e)
{
This event occurs first for each control, and then for that page. In a control, use this event to perform a final cleanup of a specific control, such as closing a control-specific database connection.
For the page itself, use this event to perform the final cleanup work, such as closing open files and database connections, or completing logging or other request-specific tasks.
Pay attention to Www.jb51.net
In the uninstall phase, the page and its controls are rendered and cannot be further changed for the response stream. If you try to invoke a method, such as the Response.Write method, the page throws an exception.
Base. OnUnload (e);
}
#endregion
}
When the page is postback, such as clicking the button, the above events will be executed again, and the Order of execution is:
1. Onpreinit
2. OnInit
3. Oninitcomplete
4. Onpreload
5. Page_Load
6. OnLoad
7. Button_Click
8. Onloadcomplete
9. OnPreRender
You can see that the Button_Click event is executed after the onload and can be tested:
Copy Code code as follows:
public partial class TestControls:System.Web.UI.Page
{
static int count = 0;
protected void Page_Load (object sender, EventArgs e)
{
Response.Write (count+ "Page_Load <br/>");
count++;
}
protected override void Onpreinit (EventArgs e)
{
Base. Onpreinit (e);
Response.Write (Count + "Onpreinit <br/>");
count++;
}
protected override void OnInit (EventArgs e)
{
Base. OnInit (e);
Response.Write (Count + "OnInit <br/>");
count++;
}
protected override void OnLoad (EventArgs e)
{
Base. OnLoad (e);
Response.Write (Count + "OnLoad <br/>");
count++;
}
protected override void Onpreload (EventArgs e)
{
Base. Onpreload (e);
Response.Write (Count + "Onpreload <br/>");
count++;
}
protected override void Onloadcomplete (EventArgs e)
{
Base. Onloadcomplete (e);
Response.Write (Count + "Onloadcomplete <br/>");
count++;
}
protected override void Oninitcomplete (EventArgs e)
{
Base. Oninitcomplete (e);
Response.Write (Count + "Oninitcomplete <br/>");
count++;
}
protected override void OnUnload (EventArgs e)
{
Base. OnUnload (e);
}
protected override void OnDataBinding (EventArgs e)
{
Base. OnDataBinding (e);
Response.Write (Count + "ondatabinding <br/>");
count++;
}
protected override void OnPreRender (EventArgs e)
{
Base. OnPreRender (e);
Response.Write (Count + "OnPreRender <br/>");
count++;
}
protected void Btngraphics_click (object sender, EventArgs e)
{
Bitmap bmp = New Bitmap (10, 10);
Graphics g = graphics.fromimage (BMP);
Response.Write (Count + "Btngraphics_click <br/>");
count++;
}
}
1. Be familiar with the whole process of operation of the request pipeline implementation program:
(1): beginrequest: Start processing requests
(2): AuthenticateRequest authorization authentication request, obtains the user authorization information
(3):P Ostauthenticaterequest get success
(4): Aunthorizerequest authorization, generally to check whether the user has access to permissions
(5):P Ostauthorizerequest: Obtain authorization
(6): Resolverequestcache: Get page Cache results
(7):P Ostresolverequestcache has obtained cache
(8) Create a Page object:P Ostmaprequesthandler
(9): AcquireRequestState get session-----First to determine whether the current Page object to implement the IRequiresSessionState interface, if implemented, from the browser sent to the request of the literary style to obtain SessionID, and to the server's session pool to obtain the corresponding session object, and finally assigned to the HttpContext session properties
(10) Postacquirerequeststate gets session
(11) PreRequestHandlerExecute: Preparing to execute Page objects
ProcessRequest method for executing page objects
(12) PostRequestHandlerExecute finish the Page object
(13) ReleaseRequestState Release Request Status
(14) Postreleaserequeststate has released request status
(15) Updaterequestcache Update Cache
(16) Postupdaterequestcache has updated cache
(17) Logrequest Log Records
(18) Postlogrequest completed Log
(19) EndRequest Complete,
Copy Code code as follows:
public class Getsession:System.Web.UI.Page, Ireadonlysessionstate
{
String ss = "";
public void Init (HttpApplication context)
{
//Here you can add each request pipeline
//Get session
in accordance with requirements. AcquireRequestState + = new EventHandler (context_acquirerequeststate);
//Get URL
context. BeginRequest + = new EventHandler (context_beginrequest);
}
void Context_acquirerequeststate (object sender, EventArgs e)
{
if (session["user"]!= null)
{
SS = session[' user ']. ToString ();
}
}
void Context_beginrequest (object sender, EventArgs e)
{
//Get the HttpApplication object for the current page request pipeline Br>httpapplication application = sender as HttpApplication;
HttpContext context = Application. Context;//Gets the context object
String url = contexts. request.url.localpath;//get URL (not including domain name and path)
}
}