Article ID: 317690 - Last Review: April 29, 2007 - Revision: 1.7 How to use the AutoEventWireup attribute in Visual Basic .NETThis article was previously published under Q317690 On This PageSUMMARY This article discusses 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. When an ASP.NET Web Application is created by using Microsoft Visual Studio .NET, the value of the AutoEventWireup attribute is set as false. This article describes how to set and to change the default values of the AutoEventWireup attribute. This article also explains the usage of this attribute with examples of ASP.NET Web Forms code that is written in Microsoft Visual Basic .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 outcome is simple code. If you set the value of the AutoEventWireup attribute to false under certain circumstances, the ASP.NET Web Application performs better. You can specify the default value of the AutoEventWireup attribute in the following locations:
By default, when the ASP.NET Web Application is created in Visual Studio .NET, the value of the AutoEventWireup attribute is set to false in the .aspx page and event handlers are automatically created. This article describes the default settings of the AutoEventWireup attribute and lists some helpful code. RequirementsThis article assumes that you are familiar with the following topics:
Configure the default values of the AutoEventWireup attributeThe value of the AutoEventWireup attribute can be declared in the <pages> section in the Machine.config file or the Web.config file as follows:The value of the AutoEventWireup attribute can also be changed in the individual Web Form. To change it in the Web Form, add the AutoEventWireup attribute to the @ Page directive, as follows: Set the value of the AutoEventWireup attribute to falseIf you want to manually hook up events to a function, use the false value of the AutoEventWireup attribute. The following samples show the code that you can use to handle the Load event of the Page object in an ASP.NET Web Form:
Set the value of the AutoEventWireup attribute to trueWhen you set the value of the AutoEventWireup attribute to false, you must manually hook up events to functions. On the other hand, when you set the value of the AutoEventWireup attribute to true, the ASP.NET page framework can automatically hook events. To code the Page_Load event handler in an ASP.NET Web Form when the value of the AutoEventWireup attribute is true, follow these steps:
Avoid setting the AutoEventWireup attribute to true when performance is keyYou must not set the value of the AutoEventWireup attribute to true if performance is a key consideration. If you set the value of the AutoEventWireup attribute to true, the ASP.NET page framework must make a call to the CreateDelegate method for every Web Form (.aspx page). Instead of relying on the automatic hookup, manually override the events from the page, as shown in code examples in this article.For more information, visit the following Microsoft Developer Network (MSDN) Web site: http://msdn.microsoft.com/library/en-us/dndotnet/html/dotnetperftips.asp
(http://msdn.microsoft.com/library/en-us/dndotnet/html/dotnetperftips.asp)
Use the AutoEventWireup attribute in other waysThe AutoEventWireup attribute is also an attribute of the @ Control directive that is used in Web User Controls. You can use theAutoEventWireup attribute in ways that are similar to those 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/
)
Overview of the ASP.NET code-behind model
312311
(http://support.microsoft.com/kb/312311/
)
How to work with code-behind class files in an ASP.NET application by using Visual Basic .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) http://msdn.microsoft.com/en-us/library/ms973839.aspx (http://msdn.microsoft.com/en-us/library/ms973839.aspx) | Article Translations
|
Back to the top
