Loading ...

ASP.NET: What is AutoEventWireup | CodeAsp.Net

ASP.NET: What is AutoEventWireup

 /5
0 (0votes)

Beginners are always confused about AutoEventWireup attribute of a Page directive. In this blog, I will explain AutoEventWireup and try to help out beginners. I hope programmers wouldn’t confuse about AutoEventWireup attribute after read this blog. When I create a new aspx page, Page directives have four attributes – Language, AutoEventWireup, CodeFile, and Inherits. 

AutoEventWireup AutoEventWireup attribute indicate whether ASP.NET pages events are auto – wired or not. It’s a Boolean attribute (accept True or false). If AutoEventWireup is set to true, some page methods are called automatically. Below is the list of methods which automatically called when AutoEventWireup is set to true -

  • Page_PreInit
  • Page_Init
  • Page_InitComplete
  • Page_PreLoad
  • Page_Load
  • Page_LoadComplete
  • Page_DataBind
  • Page_SaveStateComplete
  • Page_PreRender
  • Page_PreRenderComplete
  • Page_Unload
  • Page_Error
  • Page_AbortTransaction
  • Page_CommitTransaction
By default AutoEventWireup is true. Below I am giving you an example of AutoEventWireup.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoEventWireUpTest.aspx.cs" Inherits="AutoEventWireUpTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnTest" runat="server" Text="Click" onclick="btnTest_Click" />
    </div>
    </form>
</body>
</html>

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class AutoEventWireUpTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("This is Page Load Event..." + "<br />");
    }

    protected void Page_PreInit(object sender, EventArgs e)
    {
        Response.Write("This is Page PreInit Event..." + "<br />");
    }

    
    protected void btnTest_Click(object sender, EventArgs e)
    {
        Response.Write("This is Button Click Event after click on the button..." + "<br />");
    }
}

In above example AutoEventWireup is set to true, output is -

tr

If AutoEventWireup is set to false, output is - 

ff

There are following way to specify the AutoEventWireup attribute -

  • The Machine.config file
  • The Web.Config file
  • Web forms
  • Web user controls
The Machine.config file and Web.config file code are -

<configuration>
<system.web> 
<pages autoEventWireup="true"/> 
</system.web> 
</configuration>

ASPX Code -
<%@ Page AutoEventWireup="false" %>

ASCX Code -
<%@ Control AutoEventWireup="true" %>

Do let me know your valuable feedback or comments.

 

 

Comments (1)

   
Bass
Wow ........ Really Great!!!!!!!!
11/8/2010
 · 
by
  • :*
  • :*
  • :
 *

Top Posts