AutoEventWireup attribute in ASP.NET
AutoEventWireup is an attribute of the @ Page directive. The AutoEventWireup attribute may have a value of true or false. The value is set to false when you create a new ASP.NET Web Application.
This article describes what is AutoEventWireup attribute and its use in ASP.NET. This article also describes some of the options of this attribute by using coding and examples of the ASP.NET Web Forms code that is written in Microsoft Visual C# .NET.
You can specify a default value of the AutoEventWireup attribute in several places:
1) The Machine.config file
2) The Web.config file
3) Individual ASP.NET Web Forms (.aspx files)
4) Web User Controls (.ascx files)
The 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.
<%@ page language="C#" autoeventwireup="true" codefile="Default.aspx.cs" inherits="_Default" %>
Following four are the important points about AutoEventWireup
It is an attribute in Page directive.
It is a Boolean attribute that indicates whether the ASP.NET pages events are auto-wired.
It will have a value true or false. By default it is true.
There is no event or method associated with Page_Load. Those events whose inline event is not there but that should be executed, for that purposed AutoEventWireup="true".
Disadvantages of AutoEventWireup attribute
AutoEventWireup uses fixed naming convention for the events. Page events handlers have specific predictable names. This limits your flexibility in how you name event handlers.
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.
Another disadvantage is that performance is adversely affected, because ASP.NET searches for methods at run-time. For a Web site with high traffic volumes, the impact on performance could be significant.
AutoEventWireup="true" target is for page events only. In case of AutoEventWireup method are not case sensitive. (Page_Load or page_load both will work).
If AutoEventWireup="false" but still you want to executed Page event (Page_Load). In this you have to explicitly code for it.
Conclusion :
I hope that this article would have helped you in understanding AutoEventWireup attribute in ASP.NET. Please share your knowledge if you know more about this attribute. Your feedback and constructive contributions are always welcome.
No comments:
Post a Comment