Saturday, March 24, 2012

VS 2005 : why is the default for AutoEventWireup different for C# and VB.NET ?

OK, guys, usually I answer questions instead of asking them,
but this thing has me scratching my head.
Why is the default for AutoEventWireup different for C# and VB.NET ?
In VS 2005, if I create a new VB website using code-behind, the following Pa
ge directive is inserted
:
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" In
herits="_Default" %>
If I create a new C# website using code-behind, the following Page directive
is inserted :
<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inh
erits="_Default" %>
Is there a reason for AutoEventWireup's default setting being "false" for VB
.NET and "true" for C# ?
I asked this over at the MSDN forums, and PeteL told me this :
"The short answer to your question is that VB does this automatically, where
as C# doesn't.
The easiest way to test this is to create a Page_Init method, and put a brea
k point in it.
Then, try flipping the AutoEventWireup, in C# it will only fire when true,
but in VB it fires in either event. VB handles this for you."
My reply was :
"Your explanation tells me what happens, but I already knew that.
Why is there a difference in the way the 2 languages handle that ?
This is confusing to users.
I think this is the first instance I see of a glaringly different way
the 2 main VS.NET languages handle a .Net configuration.
Syntax differences I understand.
Why one .Net language would treat a .Net application's settings in a
different way than another .Net language is a bit more difficult to understa
nd."
So, now I ask all of you :
Why is the default for AutoEventWireup different for C# and VB.NET ?
Why does C# need AutoEventWireup set to "true" while VB.NET can make do with
"false" ?
There used to be ( pre v2 ) a difference in the way websites written in VS.N
ET
handled event wiring, because VS.NET handled the event wiring for you,
while hand-written code needed auto event wiring, but this is the first time
I see that two .Net languages need different settings to handle a .Net appli
cation.
Juan T. Llibre
ASP.NET MVP
============Oh ya, and I changed my c# templates to have it to false and override onInit
and onLoad
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:uGlKzCOAGHA.272@.tk2msftngp13.phx.gbl...
> OK, guys, usually I answer questions instead of asking them,
> but this thing has me scratching my head.
> Why is the default for AutoEventWireup different for C# and VB.NET ?
> In VS 2005, if I create a new VB website using code-behind, the following
> Page directive is inserted :
> <%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
> Inherits="_Default" %>
> If I create a new C# website using code-behind, the following Page
> directive is inserted :
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
> Inherits="_Default" %>
> Is there a reason for AutoEventWireup's default setting being "false" for
> VB.NET and "true" for C# ?
> I asked this over at the MSDN forums, and PeteL told me this :
> "The short answer to your question is that VB does this automatically,
> where as C# doesn't.
> The easiest way to test this is to create a Page_Init method, and put a
> break point in it.
> Then, try flipping the AutoEventWireup, in C# it will only fire when true,
> but in VB it fires in either event. VB handles this for you."
> My reply was :
> "Your explanation tells me what happens, but I already knew that.
> Why is there a difference in the way the 2 languages handle that ?
> This is confusing to users.
> I think this is the first instance I see of a glaringly different way
> the 2 main VS.NET languages handle a .Net configuration.
> Syntax differences I understand.
> Why one .Net language would treat a .Net application's settings in a
> different way than another .Net language is a bit more difficult to
> understand."
> So, now I ask all of you :
> Why is the default for AutoEventWireup different for C# and VB.NET ?
> Why does C# need AutoEventWireup set to "true" while VB.NET can make do
> with "false" ?
> There used to be ( pre v2 ) a difference in the way websites written in
> VS.NET
> handled event wiring, because VS.NET handled the event wiring for you,
> while hand-written code needed auto event wiring, but this is the first
> time
> I see that two .Net languages need different settings to handle a .Net
> application.
>
>
> Juan T. Llibre
> ASP.NET MVP
> ============
>
I can give you one answer. Not sure if it's accurate, but it makes sense to
me.
It's easier in the VB.Net editor to override a class member. As you know,
VB.Net offers those 2 nice little dropdowns which let you pick the class and
member you which to implement/overwrite.
The C# IDE doesn't provide this fascility. Therefore, it might have been
decided that it'd be best to use the simpler AutoEventWireup for C#. Users
don't have access to the nice IDE feature, so let's make the name easier to
remember.
The one argument against my guess is that C# intellisense allows for easy
overriding, but it's still not as easyas the VB.Net one.
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:uGlKzCOAGHA.272@.tk2msftngp13.phx.gbl...
> OK, guys, usually I answer questions instead of asking them,
> but this thing has me scratching my head.
> Why is the default for AutoEventWireup different for C# and VB.NET ?
> In VS 2005, if I create a new VB website using code-behind, the following
> Page directive is inserted :
> <%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
> Inherits="_Default" %>
> If I create a new C# website using code-behind, the following Page
> directive is inserted :
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
> Inherits="_Default" %>
> Is there a reason for AutoEventWireup's default setting being "false" for
> VB.NET and "true" for C# ?
> I asked this over at the MSDN forums, and PeteL told me this :
> "The short answer to your question is that VB does this automatically,
> where as C# doesn't.
> The easiest way to test this is to create a Page_Init method, and put a
> break point in it.
> Then, try flipping the AutoEventWireup, in C# it will only fire when true,
> but in VB it fires in either event. VB handles this for you."
> My reply was :
> "Your explanation tells me what happens, but I already knew that.
> Why is there a difference in the way the 2 languages handle that ?
> This is confusing to users.
> I think this is the first instance I see of a glaringly different way
> the 2 main VS.NET languages handle a .Net configuration.
> Syntax differences I understand.
> Why one .Net language would treat a .Net application's settings in a
> different way than another .Net language is a bit more difficult to
> understand."
> So, now I ask all of you :
> Why is the default for AutoEventWireup different for C# and VB.NET ?
> Why does C# need AutoEventWireup set to "true" while VB.NET can make do
> with "false" ?
> There used to be ( pre v2 ) a difference in the way websites written in
> VS.NET
> handled event wiring, because VS.NET handled the event wiring for you,
> while hand-written code needed auto event wiring, but this is the first
> time
> I see that two .Net languages need different settings to handle a .Net
> application.
>
>
> Juan T. Llibre
> ASP.NET MVP
> ============
>
That's the most sensible thing to do, given the current state of things.
I wonder why the VS Dev Team decided on different defaults
for the two languages, given that it's a relatively simple thing to
fix so that the defaults are standardized across languages ?
i.e., if the default for c# were to be "false", it would be just as easy to
flip it
back to "true", but at least there would be a standardized default for both
languages.
I think I'll bug it and see if we can get a standardized default for both la
nguages.
Juan T. Llibre
ASP.NET MVP
============
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net> wrot
e in message
news:uPUvLiOAGHA.2708@.TK2MSFTNGP12.phx.gbl...
> Oh ya, and I changed my c# templates to have it to false and override onIn
it and onLoad
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
> "Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
> news:uGlKzCOAGHA.272@.tk2msftngp13.phx.gbl...
vb and c# have different syntax for linking event handlers.
in vb:
'* declare control
dim withevents mycontrol as new Control()
'* declare handler - the handles clause link the event to the contol
sub myHandler (sender as object, arg as System.EventArgs) handles
mycontrol.Click
end sub
in c#
// declare control
private Control mycontrol = new Control();
// declare function
void myHandler (object sender, System.EventArgs arg)
{
}
// auto wireup generate the following statement in the init code
// so that the onclick event calls the handler
mycontrol.Click += new System.EventHandler(myHandler);
in asp 1.1 because the vs ide generated the wireup code, so you always set
autowireup to false.
-- bruce (sqlwork.com)
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:uGlKzCOAGHA.272@.tk2msftngp13.phx.gbl...
> OK, guys, usually I answer questions instead of asking them,
> but this thing has me scratching my head.
> Why is the default for AutoEventWireup different for C# and VB.NET ?
> In VS 2005, if I create a new VB website using code-behind, the following
> Page directive is inserted :
> <%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
> Inherits="_Default" %>
> If I create a new C# website using code-behind, the following Page
> directive is inserted :
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
> Inherits="_Default" %>
> Is there a reason for AutoEventWireup's default setting being "false" for
> VB.NET and "true" for C# ?
> I asked this over at the MSDN forums, and PeteL told me this :
> "The short answer to your question is that VB does this automatically,
> where as C# doesn't.
> The easiest way to test this is to create a Page_Init method, and put a
> break point in it.
> Then, try flipping the AutoEventWireup, in C# it will only fire when true,
> but in VB it fires in either event. VB handles this for you."
> My reply was :
> "Your explanation tells me what happens, but I already knew that.
> Why is there a difference in the way the 2 languages handle that ?
> This is confusing to users.
> I think this is the first instance I see of a glaringly different way
> the 2 main VS.NET languages handle a .Net configuration.
> Syntax differences I understand.
> Why one .Net language would treat a .Net application's settings in a
> different way than another .Net language is a bit more difficult to
> understand."
> So, now I ask all of you :
> Why is the default for AutoEventWireup different for C# and VB.NET ?
> Why does C# need AutoEventWireup set to "true" while VB.NET can make do
> with "false" ?
> There used to be ( pre v2 ) a difference in the way websites written in
> VS.NET
> handled event wiring, because VS.NET handled the event wiring for you,
> while hand-written code needed auto event wiring, but this is the first
> time
> I see that two .Net languages need different settings to handle a .Net
> application.
>
>
> Juan T. Llibre
> ASP.NET MVP
> ============
>
Hi, Bruce.
You're exactly right, of course.
Let me add what Scott Guthrie said about this :
---
The VB language supports the "handles" statement -- which allows you to
wire-up the bindings to event handlers on the event handler methods themselv
es.
Although you can also explicitly wire-up event handlers using the server con
trol
declaration (onclick="button1_click"), we've found that VB developers typica
lly
expect/prefer using the Handles keyword instead.
C# as a language doesn't have a concept like the "handles" keyword.
Instead, you must explicitly wire-up event definitions.
---
So, the default setting of "false" for VB.NET seems to be
a question of choice while the setting of "true" is needed for C#.
i.e., VB developers can use either method but C# developers must explicitly
wireup events.
Juan T. Llibre
ASP.NET MVP
============
"Bruce Barker" <brubar_nospamplease_@.safeco.com> wrote in message
news:uaC6LePAGHA.2256@.TK2MSFTNGP11.phx.gbl...
> vb and c# have different syntax for linking event handlers.
> in vb:
> '* declare control
> dim withevents mycontrol as new Control()
> '* declare handler - the handles clause link the event to the contol
> sub myHandler (sender as object, arg as System.EventArgs) handles mycon
trol.Click
> end sub
>
> in c#
> // declare control
> private Control mycontrol = new Control();
> // declare function
> void myHandler (object sender, System.EventArgs arg)
> {
> }
> // auto wireup generate the following statement in the init code
> // so that the onclick event calls the handler
> mycontrol.Click += new System.EventHandler(myHandler);
>
> in asp 1.1 because the vs ide generated the wireup code, so you always set
autowireup to false.
>
> -- bruce (sqlwork.com)

> "Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
> news:uGlKzCOAGHA.272@.tk2msftngp13.phx.gbl...
>

0 comments:

Post a Comment