Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Controls - Controls Server Event Handling using ASP.NET 2.0 and VB
Controls Server Event Handling using ASP.NET 2.0 and VB


ASP.NET Controls Tutorial

This tutorial will show Controls how to Handle Server Event using ASP.NET 2.0 and VB.NET

An important feature of ASP.NET is that it allows you to program Web pages using an event-based model that is similar to that in client applications.If you already have an event handler, you can bind several control events to it. These multiple events can be from the same control or one event from several different controls, as long as the events all have the same method signature. 

This tutorial only using the default namespace.The System namespace contains the EventHandler.

We use the Buttonx_Click event to connect multiple events to a single event handler. In the other word, Button1,Button2,Button3(multiple events will be connected to single event handler) will call same event handler. But this event handler will determine which Web Server Control Raised an Event. And then, we use the Button6_Click event to call eventd of  both Button4 and Button5.

Protected Sub Buttonx_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click
Dim b As Button
b = CType(sender, Button)

Select Case b.ID
Case "Button1"
Label1.Text = "You clicked the first button"
Case "Button2"
Label1.Text = "You clicked the second button"
Case "Button3"
Label1.Text = "You clicked the third button"
End Select
End Sub

Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click

End Sub

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

The front end .aspx page looks something like this:

<table width="500" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="basix" height="50">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<asp:Button ID="Button1" runat="server" OnClick="Buttonx_Click" Text="Button1" />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Buttonx_Click" Text="Button2" /><br />
<asp:Button ID="Button3" runat="server" OnClick="Buttonx_Click" Text="Button3" />
<br />
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Button4" />
<br />
<asp:Button ID="Button5" runat="server" Enabled="False" OnClick="Button5_Click" Text="Button5" /><br />
<asp:Button ID="Button6" runat="server" OnClick="Button6_Click" Text="Button6" /><br />
</td>
</tr>
</table>

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

The flow for the code behind page is as follows.

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AddHandler Button6.Click, AddressOf Button4_Click
AddHandler Button6.Click, AddressOf Button5_Click
End Sub

Protected Sub Buttonx_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click
Dim b As Button
b = CType(sender, Button)

Select Case b.ID
Case "Button1"
Label1.Text = "You clicked the first button"
Case "Button2"
Label1.Text = "You clicked the second button"
Case "Button3"
Label1.Text = "You clicked the third button"
End Select
End Sub

Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click

End Sub

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Label1.Text = "You clicked the 4th button"
End Sub

Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
Label1.Text = Label1.Text + "You clicked the 5th button"
End Sub
End Class

Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

Looking for the C# 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!





 
  Developer Resources







Server Intellect Rocks