ASP.NET page framework supports an automatic way to associate page events and methods. 
If the AutoEventWireup attribute of the Page directive is set to true. the page framework calls page events automatically, specifically the Page_Init and Page_Load methods. 
In that case, no explicit Handles clause or delegate is needed.

See the below declration. this should be create when we create new page.
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb" 

The disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, 
predictable names. This limits your flexibility in how you name your event handlers. 
Therefore, in Visual Studio, the AutoEventWireup attribute is set to false by default and the 
designer generates explicit code to bind page events to methods.

If you do set AutoEventWireup to true, Visual Studio will generate code to bind the events 
and the page framework will automatically call events based on their names. 
This can result in the same event code being called twice when the page runs. 
As a consequence, you should always leave AutoEventWireup set to false when working in Visual Studio.

More details :

Below is another way for explanation of AutoEventWireUp

If you know VB then remeber what happens if you double click on a button in "desing time" in the code an event procedure 

Button_click( ) would come up for you to enter the code.

This is a classic feature of Auto event wireup - and in VB you had to live with it.

But in .NET you can name the event handling function whatever you want and tie up the event with the corresponding handling function.

So if you have a button you could call the MyNewButton_click( ) function. But for this to be possible the "Auto Event Wire-up" property must be set to false at the page level.

Posted in |


Post a Comment