What does an AutoEventWireUp page property mean?

I do not understand what the property of the AutoEventWireUp page is AutoEventWireUp .

While surfing the net, I found many forums with discussions about this, and they all seem to me inappropriate.

Can I get a clear explanation of what this property means?

I read this article , but even this I do not understand.

+47
Mar 25 '09 at 9:42
source share
3 answers

When a page is requested, it triggers various events that are considered part of this life cycle . I keep a visual representation

+51
Mar 25 '09 at 9:54
source share

To add to previous answers; automatic hooks are used from TemplateControl.HookUpAutomaticHandlers . This method calls TemplateControl.GetDelegateInformationWithNoAssert , which contains methods that are considered event handlers.

This is, in System.Web, version 2.0:

  • In all classes originating from Page: Page_PreInit , Page_PreLoad , Page_LoadComplete , Page_PreRenderComplete , Page_InitComplete , Page_SaveStateComplete .

  • In all classes derived from TemplateControl: Page_Init , Page_Load , Page_DataBind , Page_PreRender , Page_UnLoad , Page_Error .`

  • Transaction support for all classes originating from TemplateControl:

    • Page_AbortTransaction , or if it does not exist, OnTransactionAbort
    • Page_CommitTransaction , or if it does not exist, OnTransactionCommit

System.Web, version 4.0, introduced Page_PreRenderCompleteAsync for all classes retrieved from the page. This method, if any, will be registered with Page.RegisterAsyncTask and will be executed automatically "immediately before the PreRenderComplete event" (source: Page.ExecuteRegisteredAsyncTasks ). This method seems very undocumented, which suggests that it would be desirable to just call Page.RegisterAsyncTask using its own method.

+26
Mar 25 '09 at 10:16
source share

As mentioned in the article, if you enabled AutoEventWireUp, asp.net automatically recognizes that you have a method with the syntax page_load and is called automatically:

 private void Page_Load(object sender, System.EventArgs e) { } 

This gives you cleaner code at the cost of some (very) small overhead. Please note: if you do not specify it, you must explicitly specify asp.net with which you want to handle the page load event:

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

Please note that this applies to other events on the page as it uses the naming convention as Page_Event.

+8
Mar 25 '09 at 9:51
source share



All Articles