Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Using "Handles" vb vs. c#

 
Thread Tools Search this Thread
Old 08-30-2006, 04:51 PM   #1
Default 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);
}




sck10
  Reply With Quote
Old 08-30-2006, 05:08 PM   #2
Juan T. Llibre
 
Posts: n/a
Default Re: Using "Handles" vb vs. c#



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" <> wrote in message news:...
> 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);
> }
>
>



  Reply With Quote
Old 08-30-2006, 06:46 PM   #3
sck10
 
Posts: n/a
Default Re: Using "Handles" vb vs. c#



Thanks Juan, your explanation was very helpful...


"Juan T. Llibre" <> wrote in message
news:ej$...
> 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" <> wrote in message
> news:...
>> 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);
>> }
>>
>>

>
>



  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump