ASP. NET page execution order such as: Onpreinit (), OnInit ()

Source: Internet
Author: User

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
As you can see, the Button_Click event is executed after onload and can be tested:

 Public Partial classtestcontrols:system.web.ui.page{Static intCount =0; protected voidPage_Load (Objectsender, EventArgs e) {Response.Write (Count+"Page_Load <br/>"); Count++; }        protected Override voidOnpreinit (EventArgs e) {Base.            Onpreinit (e); Response.Write (Count+"onpreinit <br/>"); Count++; }        protected Override voidOnInit (EventArgs e) {Base.            OnInit (e); Response.Write (Count+"OnInit <br/>"); Count++; }        protected Override voidOnLoad (EventArgs e) {Base.            OnLoad (e); Response.Write (Count+"OnLoad <br/>"); Count++; }        protected Override voidonpreload (EventArgs e) {Base.            Onpreload (e); Response.Write (Count+"onpreload <br/>"); Count++; }        protected Override voidOnloadcomplete (EventArgs e) {Base.            Onloadcomplete (e); Response.Write (Count+"onloadcomplete <br/>"); Count++; }        protected Override voidOninitcomplete (EventArgs e) {Base.            Oninitcomplete (e); Response.Write (Count+"oninitcomplete <br/>"); Count++; }       protected Override voidOnUnload (EventArgs e) {Base.        OnUnload (e); }        protected Override voidondatabinding (EventArgs e) {Base.            OnDataBinding (e); Response.Write (Count+"ondatabinding <br/>"); Count++; }        protected Override voidOnPreRender (EventArgs e) {Base.            OnPreRender (e); Response.Write (Count+"OnPreRender <br/>"); Count++; }        protected voidBtngraphics_click (Objectsender, EventArgs e) {            //Bitmap bmp = new Bitmap (10, 10); //Graphics g = graphics.fromimage (BMP);Response.Write (Count +"Btngraphics_click <br/>"); Count++; }}

ASP. NET page execution order such as: Onpreinit (), OnInit ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.