What is AutoEventWireup?http://forums.asp.net/t/932513.aspx/1?What+is+AutoEventWireup+Sun, 06 Jul 2008 06:51:35 -04009325131096656http://forums.asp.net/p/932513/1096656.aspx/1?What+is+AutoEventWireup+What is AutoEventWireup? When I created zipsearch.aspx file, the following<br> code was generated:<br> &lt;%@ Page Language=&quot;<a class="iAs" href="http://www.tek-tips.com/viewthread.cfm?qid=1143918&amp;page=1#" target="_blank" style="color:darkgreen; border-bottom:darkgreen 1px solid; background-color:transparent; text-decoration:underline">vb</a>&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;zipsearch.aspx.vb&quot; Inherits=&quot;ZipcodeDB.zipsearch&quot;%&gt;<br> <br> What is AutoEventWireup? - what is the effect is set to&nbsp;&nbsp;true or false?<br> <br> Thanks<br> 2005-10-28T18:04:52-04:001096676http://forums.asp.net/p/932513/1096676.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? Hi,<br> <br> this is taken from the MSDN library:<br> <br> <em>the ASP.NET page framework also supports an automatic way to associate page events and methods. If the <b>AutoEventWireup</b> attribute of the </em><a href="http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconPage.asp"><em>Page</em></a><em> directive is set to <b>true</b> (or if it is missing, since by default it is <b>true</b>), the page framework calls page events automatically, specifically the <b>Page_Init</b> and <b>Page_Load</b> methods. In that case, no explicit <b>Handles</b> clause or delegate is needed.</em> <p><em>The disadvantage of the <b>AutoEventWireup</b> attribute is that it requires that the page event handlers have specific, predictable names. This limits your flexibility in how you name your event handlers. Therefore, in Visual Studio, the <b>AutoEventWireup</b> attribute is set to <b>false</b> by default and the designer generates explicit code to bind page events to methods. </em></p> <p><em>If you do set <b>AutoEventWireup</b> to <b>true</b>, 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 <b>AutoEventWireup</b> set to <b> false</b> when working in Visual Studio.<br> <br> </em>Resource: <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconWebFormsEventModel.asp"> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconWebFormsEventModel.asp</a><br> <br> Grz, Kris.</p> 2005-10-28T18:31:42-04:001096677http://forums.asp.net/p/932513/1096677.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? Try a lookup in Visual Studio Help-&gt;Index. It will tell you all that you want to know about it, and then some.<br> <br> NC...<br> 2005-10-28T18:32:50-04:001097153http://forums.asp.net/p/932513/1097153.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>To explain it a lil more </p> <p>If you know VB then remeber what happens if you double click on a button in &quot;desing time&quot; in the code an event procedure&nbsp;</p> <p><em><strong>Button_click( )</strong></em>&nbsp;would come up for you to enter the code.</p> <p>This is a classic feature of Auto event wireup - and in VB you had to live with it.</p> <p>But in .NET you can name the event&nbsp;handling function&nbsp;whatever you want and tie up the event with the corresponding handling function.<br> <br> So if you have a button you could call the <strong><em>MyNewButton_click( )</em></strong> function. But for this to be possible the &quot;Auto Event Wire-up&quot; property must be set to false at the page level.<br> <br> Hope this helps [:)]<br> <br> </p> 2005-10-29T12:18:55-04:002105944http://forums.asp.net/p/932513/2105944.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? I'm very new to ASP.NET, so correct me if I am wrong, but I don't think it matters whether AutoEventWireup is true of false, you can still name your event handling functions whatever you want. <br> <br> Eg. in your .aspx file you can have something like: <br> <br> [code] [/code] <br> <br> And in your CodeBehind(.aspx.cs) have <br> <br> [code] protected void dance_monkey_dance(object sender, System.EventArgs e){ //Stuff } [/code] <br> <br> Note that the handling function has to be protected, not private, as it is referenced in the markup. However, for AutoEventWireup to work, you still have to use the Page_Load and Page_Init names for those functions.<br> <br> Cheers,<br> Inno 2008-01-12T16:32:55-05:002106485http://forums.asp.net/p/932513/2106485.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>Inno,</p> <p>You are&nbsp;replying to a post that is over 2 years old? Why? For what purpose?</p> <p>NC...</p> <p>&nbsp;</p> 2008-01-13T10:34:13-05:002106495http://forums.asp.net/p/932513/2106495.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>[:S] </p> <p><font color="#ff0000" size="4">WOW</font></p> <p><font size="3">They really do come back from the dead</font> <font size="1">(to the top of the list.)</font></p> <p>&nbsp;</p> <p>That sucks big time, Um hello <strong><em><u><font size="4">INNO</font></u></em></strong>&nbsp;read this please <font size="4">ALL</font> of it &gt;&gt;&gt;&gt; <a class="" href="http://forums.asp.net/t/1180041.aspx"> Getting Started</a></p> 2008-01-13T10:50:18-05:002106794http://forums.asp.net/p/932513/2106794.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? NC, <br> <br> I came across this post googling &quot;AutoEventWireup&quot; - it is the first result on Google, so although this post may be long dead in the context of our community, that is far from being true in the wider sense. The post was useful to me, but it also contained some misinformation. I made the call to fix it, granted, at a cost to this community, but hopefully for a greater benefit to all. My sincerest apologies to anyone who didn't get an answer they needed because of this. <br> <br> -Inno 2008-01-13T18:10:55-05:002108117http://forums.asp.net/p/932513/2108117.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>In that case you should start a new post.</p> <p>NC...</p> <p>&nbsp;</p> 2008-01-14T12:00:10-05:002108259http://forums.asp.net/p/932513/2108259.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>...and how would that help someone finding this page via a google search and finding mis-information contained within?&nbsp;</p> 2008-01-14T13:05:16-05:002116980http://forums.asp.net/p/932513/2116980.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>I think by auto wire-up, they mean that buttons will automatically map to buttonName_OnClick. This isn't the same as explicitly declaring OnClick=&quot;buttonName_Click&quot;.<br> <br> &nbsp;</p> 2008-01-18T03:19:54-05:002117053http://forums.asp.net/p/932513/2117053.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>&nbsp;</p> <p>Check this out... <a href="http://forums.asp.net/p/932513/1096656.aspx">http://forums.asp.net/p/932513/1096656.aspx</a></p> <p>Also note that the default value for aspx pages in C# is true &amp; for VB.NET is false.</p> <p>HTH</p> 2008-01-18T04:01:26-05:002237162http://forums.asp.net/p/932513/2237162.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>Autoeventwireup has nothing to do with the button hanlders.It works only for Page Events.&nbsp;</p> <p>for more details see the article by using link below.<br> </p> <p>&nbsp;<br> http://blogs.ittoolbox.com/c/coding/archives/autoeventwireup-attribute-9312</p> <p>&nbsp;</p> <blockquote><span class="icon-blockquote"></span> <h4>moredotnet</h4> <p></p> <p>&nbsp;</p> <p>Check this out... <a href="http://forums.asp.net/p/932513/1096656.aspx">http://forums.asp.net/p/932513/1096656.aspx</a></p> <p>Also note that the default value for aspx pages in C# is true &amp; for VB.NET is false.</p> <p>HTH</p> </blockquote> <p>&nbsp;</p> 2008-03-17T11:53:14-04:002237180http://forums.asp.net/p/932513/2237180.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <p>I also believe that this statement: <em><strong>Also note that the default value for aspx pages in C# is true &amp; for VB.NET is false.</strong></em> is in error as in the link that Ulfat posted, it says:</p> <p><em><strong>AutoEventWireup is false when we create a new web application and event handlers are automatically created. We can find this in the Initialize Component method...</strong></em></p> <p>NC...</p> <p><strong><em></em></strong>&nbsp;</p> 2008-03-17T12:01:28-04:002469576http://forums.asp.net/p/932513/2469576.aspx/1?Re+What+is+AutoEventWireup+Re: What is AutoEventWireup? <span style="font-size:10pt; color:black"><font face="Calibri">The best way to see the working of this attribute would be:</font></span> <ul type="disc"> <li class="MsoNormal" style="margin:0in 0in 10pt; color:black; line-height:normal"> <font face="Calibri"><span style="font-size:10pt">Declare a </span><span lang="CS" style="color:blue">string</span><span lang="CS" style="font-size:10pt"> </span><span style="font-size:10pt">variable </span><span style="color:#990000">msg</span><span style="font-size:10pt"> as </span><span lang="CS" style="color:blue">public</span><span style="font-size:10pt"> in <i>WebForm1.aspx.cs</i>. </span></font></li><li class="MsoNormal" style="margin:0in 0in 10pt; color:black; line-height:normal"> <font face="Calibri"><span style="font-size:10pt">In the HTML section of <i>WebForm1.aspx</i>, enter the following code in the </span><span style="color:blue">&lt;</span><span style="color:#990000">Head</span><span style="color:blue">&gt;</span><span style="font-size:10pt"> section:<span style="">&nbsp; </span>&lt;%Response.Write(msg);%&gt;</span></font></li></ul> <font face="Calibri"><span style="font-size:10pt; color:black">In the </span><span style="color:#990000">Page_Load</span><span style="font-size:10pt; color:black">, you could enter a value for the variable </span><span style="color:#990000">msg</span><span style="font-size:10pt; color:black"> declared.</span></font><span style="font-size:10pt; color:black"><font face="Calibri">Msg= We are in Page_Load();</font></span><font face="Calibri"><span style="font-size:10pt; color:black">On running the application, you will get the message <b>We are in Page_Load()</b> [hereafter referred to as message]. Note: this is in the default case where the attribute is set to </span><span lang="CS" style="color:blue">false</span><span style="font-size:10pt; color:black">.</span></font><font face="Calibri"><span style="font-size:10pt; color:black">Now try commenting the event handler code for the </span><span style="color:#990000">Page_Load</span><span style="font-size:10pt; color:black"> in the <i>aspx.cs</i> file; and set the </span><span style="color:#990000">AutoEventWireup</span><span style="font-size:10pt; color:black"> attribute to </span><span lang="CS" style="color:blue">false</span><span style="font-size:10pt; color:black"> in the <i>.aspx</i> page. On running the application this time, <b>you will not get the message</b>.</span></font><font face="Calibri"><span style="font-size:10pt; color:black">Now with the event handler code for the </span><span style="color:#990000">Page_Load</span><span style="font-size:10pt; color:black"> in the <i>aspx.cs</i> file still commented; set the </span><span style="color:#990000">AutoEventWireup</span><span style="font-size:10pt; color:black"> attribute to </span><span lang="CS" style="color:blue">true</span><span style="font-size:10pt; color:black"> in the .aspx page. On running the application this time, <b>you will get the message</b>.</span></font><font face="Calibri"><b><span style="font-size:10pt; color:black">Reason</span></b><span style="font-size:10pt; color:black">: In the case where </span><span style="color:#990000">AutoEventWireup</span><span style="font-size:10pt; color:black"> attribute is set to </span><span lang="CS" style="color:blue">false</span><span style="font-size:10pt; color:black"> (by default), event handlers are automatically required for </span><span style="color:#990000">Page_Load</span><span style="font-size:10pt; color:black"> or </span><span style="color:#990000">Page_Init</span><span style="font-size:10pt; color:black">. However, when we set the value of the </span><span style="color:#990000">AutoEventWireup</span><span style="font-size:10pt; color:black"> attribute to </span><span lang="CS" style="color:blue">true</span><span style="font-size:10pt; color:black">, the ASP.NET runtime does not require events to specify event handlers like </span><span style="color:#990000">Page_Load</span><span style="font-size:10pt; color:black"> or </span><span style="color:#990000">Page_Init</span><span style="font-size:10pt; color:black">.</span></font><font face="Calibri"><span style="font-size:10pt; color:black">A thing to be kept in mind is that the </span><span style="color:#990000">AutoEventWireup</span><span style="font-size:10pt; color:black"> attribute of the </span><span style="color:#990000">Page</span><span style="font-size:10pt; color:black"> directive is <u>set to </u></span><u><span lang="CS" style="color:blue">true</span></u><u><span style="font-size:10pt; color:black"> by default for the machine</span></u><span style="font-size:10pt; color:black"> (check out the value of this attribute in the <i>machine.config</i>) but <u>set to </u></span><u><span lang="CS" style="color:blue">false</span></u><u><span style="font-size:10pt; color:black"> by default for a <i>.aspx</i> page</span></u><span style="font-size:10pt; color:black">). So if it is missing, since by default it is </span><span lang="CS" style="color:blue">true</span><span style="font-size:10pt; color:black"> (i.e., at the machine level), the page framework calls page events automatically, specifically the </span><span style="color:#990000">Page_Init</span><span style="font-size:10pt; color:black"> and </span><span style="color:#990000">Page_Load</span><span style="font-size:10pt; color:black"> methods. In that case, no explicit </span><span lang="CS" style="color:#990000">Handles</span><span style="font-size:10pt; color:black"> clause or delegate is needed.</span></font> <p>&nbsp;</p> 2008-07-06T06:51:35-04:00