Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does AutoEventWireUp page property mean?

I don't understand what the AutoEventWireUp page property is responsible for.

I've read through this article, but even that I don't understand.

like image 599
chester89 Avatar asked Mar 25 '09 09:03

chester89


People also ask

What is the purpose of AutoEventWireup attribute?

AutoEventWireup is an attribute in Page directive. AutoEventWireup is a Boolean attribute that indicates whether the ASP.NET pages events are auto-wired. AutoEventWireup will have a value true or false. By default it is true.

Which attribute is an automatic way to bind the event to method?

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.


1 Answers

When a Page is requested, it raises various events which are considered to be part of it's lifecycle. I keep the visual representation created by Peter Bromberg handy with me.

The AutoEventWireUp property when True, automatically wires up some of these built-in events in the Page life cycle to their handlers. This means that you do not need to explicitly attach these events (using the Handles keyword, for instance, in VB).

Examples of these built-in events would be Page_Init and Page_Load.

If you set AutoEventWireUp to True and provide explicit wiring up of the EventHandlers, you will find them being executed twice! This is one reason why Visual Studio keeps this attribute set to false by default.

Edit: (after Chester89's comment)


It is useful to note that the default value of the AutoEventWireUp attribute of the Page is true, while the default value of the AutoEventWireUp property of the Page class is false

like image 113
Cerebrus Avatar answered Oct 11 '22 21:10

Cerebrus