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.

http://support.microsoft.com/kb/324151

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

C# code:

void Page_Load(Object sender, EventArgs e)
{
// Manually register the event-handling method for the Click
// event of the Button control.
Button1.Click += new EventHandler(this.SubmitBtn_Click);
}

void SubmitBtn_Click(Object sender, EventArgs e)
{
Message.Text=”Hello World!!”;
}

Button Click Example

Click the Submit button.

Here is some good links talk about the AutoEventWireup
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclick(VS.71).aspx
http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx

Advertisements