What is the AutoEventWireup attribute in ASP.NET?

In today's post i am going to cover "What is the AutoEventWireup attribute in ASP.NET?
In the previous tutorials i have explained sealed class ,Abstract class ,Ajax call,Ref and Out Keyword  etc.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"Inherits="_Default" %>


There is an automated way provided by ASP.Net Page framework to associate page event and methods.If the AutoEventWireup attribute of the Page directive is set to true, the page framework calls page events automatically. There is no explicit Handles or delegate is needed to call page events and methods.


  1. Default value of AutoEventWireup is set to false.
  2. AutoEventWireup is a Boolean attribute.(If set to true then page events are auto wired.)
To understand it better, set the AutoEventWireup="false" and check application - Page_Load() and Page_Init() won't fire automatically.

Disadvantages of AutoEventWireup

  1. 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.
  2. 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.
  3. 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.

Conclusion

I hope that this article would have helped you in understanding the AutoEventWireup attribute in ASP.NET.Your feedback and constructive contributions are welcome.


Thanks.


What is the AutoEventWireup attribute in ASP.NET? What is the AutoEventWireup attribute in ASP.NET? Reviewed by CodiBucket on 08:42 Rating: 5

No comments:

Facebook

Powered by Blogger.