473,545 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="gvSearchLis t" runat="server"
DataSourceID="d sSearchList"
DataKeyNames="S erviceIdea_ID"
OnSelectedIndex Changed="gvSear chList_Selected IndexChanged">
VB
=======
Protected Sub gvSearchList_Se lectedIndexChan ged(ByVal sender As Object,
ByVal e As EventArgs) Handles gvSearchList.Se lectedIndexChan ged

Me.fvServiceIde a.ChangeMode(Fo rmViewMode.Read Only)

End Sub
C#
=======
protected void gvSearchList_Se lectedIndexChan ged(object sender, EventArgs e)
{
this.fvServiceI dea.ChangeMode( FormViewMode.Re adOnly);
}
Aug 30 '06 #1
2 4387
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="butto n1_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="Button 1_Click"
declaratively :
Sub Button1_Click(B yVal 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(B yVal s As Object, ByVal e As EventArg) Handles Me.Button1.Clic k
' 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.n ospamwrote in message news:Oi******** ******@TK2MSFTN GP04.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="gvSearchLis t" runat="server"
DataSourceID="d sSearchList"
DataKeyNames="S erviceIdea_ID"
OnSelectedIndex Changed="gvSear chList_Selected IndexChanged">
VB
=======
Protected Sub gvSearchList_Se lectedIndexChan ged(ByVal sender As Object, ByVal e As EventArgs)
Handles gvSearchList.Se lectedIndexChan ged

Me.fvServiceIde a.ChangeMode(Fo rmViewMode.Read Only)

End Sub
C#
=======
protected void gvSearchList_Se lectedIndexChan ged(object sender, EventArgs e)
{
this.fvServiceI dea.ChangeMode( FormViewMode.Re adOnly);
}


Aug 30 '06 #2
Thanks Juan, your explanation was very helpful...
"Juan T. Llibre" <no***********@ nowhere.comwrot e in message
news:ej******** ******@TK2MSFTN GP06.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="butto n1_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="Button 1_Click"
declaratively :
Sub Button1_Click(B yVal 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(B yVal s As Object, ByVal e As EventArg) Handles
Me.Button1.Clic k
' 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.n ospamwrote in message
news:Oi******** ******@TK2MSFTN GP04.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:GridVie w ID="gvSearchLis t" runat="server"
DataSourceID="d sSearchList"
DataKeyNames="S erviceIdea_ID"
OnSelectedIndex Changed="gvSear chList_Selected IndexChanged">
VB
=======
Protected Sub gvSearchList_Se lectedIndexChan ged(ByVal sender As Object,
ByVal e As EventArgs) Handles gvSearchList.Se lectedIndexChan ged

Me.fvServiceIde a.ChangeMode(Fo rmViewMode.Read Only)

End Sub
C#
=======
protected void gvSearchList_Se lectedIndexChan ged(object sender, EventArgs
e)
{
this.fvServiceI dea.ChangeMode( FormViewMode.Re adOnly);
}



Aug 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3618
by: Rohit | last post by:
Hi, Threads in the .NET Framework 1.1 (and possibly in 1.0 also) leak "Event" handles, by Event handles I mean Win32 Event handles which can be monitored using the ProcessExplorer from www.sysinternals.com, or even simply look at the Handle count in the good old windows TaskManager. To demonstrate the problem, all I did was created a basic...
12
1484
by: johnb41 | last post by:
This question is regarding the "Handles" part of a routine, for example: Handles Button1.Click On Form2 (a User Control) I have a button. Here's it's code: Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '...
7
2606
by: Simon Verona | last post by:
I have a problem in my application which I believe is due to open handles.. . The symptom that users report is that after they have been using the application for a while, it will randomly just crash with an exception report (I've not got the details of the error, but I'm working on that now!). I'm trying to reproduce the circumstances by...
16
1800
by: abc my vclass | last post by:
C# has VB's "with" command? I like VB's with command, why don't know C# has it or not?
6
1551
by: antonyliu2002 | last post by:
Right now I put my VB code in the aspx pages. I would prefer to use codebehind, especially many of my VB functions may be shared across multiple aspx pages. I've tried a few pages with codebehind by follwing some examples on the Web and they work just fine. However, I am scared away from codebehind by such extenstions as "Handles...
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7918
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7766
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5981
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
715
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.