Using "Handles" vb vs. c#

S

sck10

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_SelectedIndexChanged">


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.ReadOnly);
}
 
J

Juan T. Llibre

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,293
Latest member
Hue Tran

Latest Threads

Top