ASP.NET page_init event?

后端 未结 7 1445
梦谈多话
梦谈多话 2021-02-01 17:52

I am using ASP.NET 3.5 and i used earlier 1.1 i am having difficulty to find where can i attach/declare the page init event ?

In 1.1 there was auto generated code which

7条回答
  •  暖寄归人
    2021-02-01 18:21

    ASP.NET 2.0 changed the default designing/compilation model.

    By default AutoEventWireup is set to true, which instructs compiler to automatically attach event handlers from the code behind using naming convention, so when you write:

    protected void Page_Load(...)
    {
    
    }
    

    it automatically puts this code in behind the scenes:

    this.Load += new EventHandler(this.Page_Load)
    

    This was previously done by InitialiseComponent() (i believe).

    Nonetheless, the answer is to write the code yourself:

    protected void Page_Init(object sender, EventArgs e)
    {
        // do the bartman
    }
    

提交回复
热议问题