Article ID: 324151 - Last Review: April 29, 2007 - Revision: 1.8 How to use the AutoEventWireup attribute in an ASP.NET Web Form by using Visual C# .NETThis article was previously published under Q324151 On This PageSUMMARYThis article discusses the locations where the AutoEventWireup attribute can be used, the values that the AutoEventWireup attribute accepts, and how to use the AutoEventWireup attribute effectively in Microsoft ASP.NET Web Forms. 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 how to set and to change the default values of the AutoEventWireup attribute. This article also describes some of the options of this attribute by using examples of the ASP.NET Web Forms code that is written in Microsoft Visual C# .NET. You may use the AutoEventWireup attribute to code ASP.NET Web Forms and Web User Controls. When you set the value of the AutoEventWireup attribute to true, the code in ASP.NET Web Forms and in Web User Controls is simple. However, when you use the false value in certain circumstances, you may receive better performance. You can specify a default value of the AutoEventWireup attribute in several places:
When you use Microsoft Visual Studio .NET, the value of the AutoEventWireup attribute is set to false and the designer automatically generates event handlers. This article describes the default settings of the AutoEventWireup attribute and shows you some helpful code. RequirementsThis article assumes that you are familiar with the following topics:
Configuration of the AutoEventWireup attribute default valuesThe AutoEventWireup attribute can be declared in the <pages> section in the Machine.config file or the Web.config file. In either of these XML-based files, use the following syntax:To change the value of the AutoEventWireup attribute in the individual ASP.NET Web Form, add the AutoEventWireup attribute to the @ Page directive, as follows: When the value of the AutoEventWireup attribute is falseIf you want to manually hook up events to an event handler, set the value of the AutoEventWireup attribute to false. The following sample shows the code that you can use to handle the Load event of the Page object in an ASP.NET Web Form:
When the value of the AutoEventWireup attribute is trueWhen you set the value of the AutoEventWireup attribute to false, you must manually hook up events to event handlers. When you set the value of the AutoEventWireup attribute to true, the ASP.NET page framework can automatically raise events. The following sample describes how to code a Page_Load event handler in an ASP.NET Web Form when the value of the AutoEventWireup attribute is true.
When to avoid setting the value of the AutoEventWireup attribute to trueIf performance is a key consideration, do not set the value of the AutoEventWireup attribute to true. The AutoEventWireup attribute requires the ASP.NET page framework to make a call to the CreateDelegate function for every ASP.NET Web Form page. Instead of using automatic hookup, you must manually override the events from the page. For more information, visit the following Microsoft Developer Network (MSDN) Web site:http://msdn.microsoft.com/en-us/library/ms973839.aspx
(http://msdn.microsoft.com/en-us/library/ms973839.aspx)
Other places where you can use the AutoEventWireup attributeThe AutoEventWireup attribute is also an attribute of the @ Control directive that is used in Web User Controls (.ascx) pages. You can use the AutoEventWireup attribute in ways that are similar to those that are described in this article.REFERENCES For additional
information, click the following article numbers to view the articles in the
Microsoft Knowledge Base: 303247
(http://support.microsoft.com/kb/303247/
)
ASP.NET Code-Behind Model overview
312311
(http://support.microsoft.com/kb/312311/
)
How to work with CodeBehind class files in ASP.NET
For more information, visit the following MSDN Web sites: http://msdn2.microsoft.com/en-us/library/ydy4x04a(vs.71).aspx
(http://msdn2.microsoft.com/en-us/library/ydy4x04a(vs.71).aspx)
http://msdn.microsoft.com/en-us/library/fy30at8h.aspx (http://msdn.microsoft.com/en-us/library/fy30at8h.aspx) http://msdn.microsoft.com/en-us/library/at2tetf6(VS.71).aspx (http://msdn.microsoft.com/en-us/library/at2tetf6(VS.71).aspx) http://msdn2.microsoft.com/en-us/library/edzehd2t(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/edzehd2t(vs.71).aspx) | Article Translations
|
Back to the top
