The ASP.NET page framework also supports an automatic way to associate page events and methods. If the AutoEventWireup attribute of the Page directive is set to true (or if it is missing, since by default it is true),
- 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
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"Inherits="WebApplication2._Default" %>
the page framework calls page events automatically, specifically the Page_Init andPage_Load methods. In that case, no explicit Handles clause or delegate is needed.
Example 1
With AutoEventWireup="true"
Code
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Sri");
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("
Button Click");
Button Click");
}
When we click Button then both page load and button click event get fired.
OUTPUT
Sri
Button Click
Button Click
Example 2
With AutoEventWireup="false"
Now set the AutoEventWireup propoerty false
Again click the Button Event this time only click event get fired.
OUTPUT
Button Click