471,086 Members | 814 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

Using "Handles" vb vs. c#

Hello,

Is there an equivalent to using "Handles" in the codebehind for c#? Or do I
have to declare every event in the GridView control like the following:

<asp:GridView ID="gvSearchList" runat="server"
DataSourceID="dsSearchList"
DataKeyNames="ServiceIdea_ID"
OnSelectedIndexChanged="gvSearchList_SelectedIndex Changed">
VB
=======
Protected Sub gvSearchList_SelectedIndexChanged(ByVal sender As Object,
ByVal e As EventArgs) Handles gvSearchList.SelectedIndexChanged

Me.fvServiceIdea.ChangeMode(FormViewMode.ReadOnly)

End Sub
C#
=======
protected void gvSearchList_SelectedIndexChanged(object sender, EventArgs e)
{
this.fvServiceIdea.ChangeMode(FormViewMode.ReadOnl y);
}
Aug 30 '06 #1
2 4275
The VB language supports the "handles" statement -- which allows you to
wire-up the bindings to event handlers on the event handler methods themselves.
Although you can also explicitly wire-up event handlers using the server control
declaration (onclick="button1_click"), VB developers typically 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.
i.e., VB developers can use either method but C# developers must explicitly wireup events.
You may set AutoEventWireup="true" for VB.Net.
In VS.Net 200x, this means that you can skip the "Handles ...." statement,
provided the method is named correctly.
E.g., if you have AutoEventWireup set to true, this method in a Codebehind file would handle the
Click Event of the Button Control with ID "Button1" without using onclick="Button1_Click"
declaratively :
Sub Button1_Click(ByVal s As Object, ByVal e As EventArg)
' Look, no Handles
End Sub
If you set AutoEventWireup="false", you would need to add the Handles:
Sub Button1_Click(ByVal s As Object, ByVal e As EventArg) Handles Me.Button1.Click
' Need Handles
End Sub
I hope this makes the issue a bit clearer for you.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================

"sck10" <sc***@online.nospamwrote in message news:Oi**************@TK2MSFTNGP04.phx.gbl...
Hello,

Is there an equivalent to using "Handles" in the codebehind for c#? Or do I have to declare every
event in the GridView control like the following:

<asp:GridView ID="gvSearchList" runat="server"
DataSourceID="dsSearchList"
DataKeyNames="ServiceIdea_ID"
OnSelectedIndexChanged="gvSearchList_SelectedIndex Changed">
VB
=======
Protected Sub gvSearchList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Handles gvSearchList.SelectedIndexChanged

Me.fvServiceIdea.ChangeMode(FormViewMode.ReadOnly)

End Sub
C#
=======
protected void gvSearchList_SelectedIndexChanged(object sender, EventArgs e)
{
this.fvServiceIdea.ChangeMode(FormViewMode.ReadOnl y);
}


Aug 30 '06 #2
Thanks Juan, your explanation was very helpful...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:ej**************@TK2MSFTNGP06.phx.gbl...
The VB language supports the "handles" statement -- which allows you to
wire-up the bindings to event handlers on the event handler methods
themselves.
Although you can also explicitly wire-up event handlers using the server
control
declaration (onclick="button1_click"), VB developers typically
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.
i.e., VB developers can use either method but C# developers must
explicitly wireup events.
You may set AutoEventWireup="true" for VB.Net.
In VS.Net 200x, this means that you can skip the "Handles ...." statement,
provided the method is named correctly.
E.g., if you have AutoEventWireup set to true, this method in a Codebehind
file would handle the
Click Event of the Button Control with ID "Button1" without using
onclick="Button1_Click"
declaratively :
Sub Button1_Click(ByVal s As Object, ByVal e As EventArg)
' Look, no Handles
End Sub
If you set AutoEventWireup="false", you would need to add the Handles:
Sub Button1_Click(ByVal s As Object, ByVal e As EventArg) Handles
Me.Button1.Click
' Need Handles
End Sub
I hope this makes the issue a bit clearer for you.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================

"sck10" <sc***@online.nospamwrote in message
news:Oi**************@TK2MSFTNGP04.phx.gbl...
>Hello,

Is there an equivalent to using "Handles" in the codebehind for c#? Or
do I have to declare every event in the GridView control like the
following:

<asp:GridView ID="gvSearchList" runat="server"
DataSourceID="dsSearchList"
DataKeyNames="ServiceIdea_ID"
OnSelectedIndexChanged="gvSearchList_SelectedIndex Changed">
VB
=======
Protected Sub gvSearchList_SelectedIndexChanged(ByVal sender As Object,
ByVal e As EventArgs) Handles gvSearchList.SelectedIndexChanged

Me.fvServiceIdea.ChangeMode(FormViewMode.ReadOnly)

End Sub
C#
=======
protected void gvSearchList_SelectedIndexChanged(object sender, EventArgs
e)
{
this.fvServiceIdea.ChangeMode(FormViewMode.ReadOnl y);
}



Aug 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by johnb41 | last post: by
16 posts views Thread by abc my vclass | last post: by
6 posts views Thread by antonyliu2002 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.