FREE & Commercial Dreamweaver MX Extensions from WebXeL.com Ltd
 
Web Design and Web Hosting


Dissect and explain an event procedure

Ok now we will take look at a typical event procedure method for a button click, first look at the event procedure in its entirety then we will explain each of the procedures components in more detail.

C#
void Button1_Click(object sender, System.EventArgs e)
{
    //your code here
}

VB
Sub Button1_Click(sender As Object, e As System.EventArgs)
    'your code here
End Sub

Button control tag:

<asp:button OnClick="Button1_Click" ID="Button1" runat="server" Text="OK" />

Next we look at the "sender" object, often defined as Src in Dreamweaver's default code, this sender object is an object reference to the Control or class instance that raised the event, in the case of our example this will contain an object reference to the button that was clicked, a bit later we will see how we can use this sender object to identify the control that raised the event when the event procedure is wired to multiple controls, for now we will stay with explaining the event procedures components.

Next we look at the "e" class object, often defined as E in Dreamweaver's default code, the e object is an EventArgs class object that can contain information about the event and the sender control, this EventArgs class is known as a Delegate or Event Delegate. In the case of a DataGrid's ItemCreated event procedure which is raised each time a new DataGrid row is created, the e object will contain a property called Item which itself contains a property called ItemIndex, you can therefore find out precisely what the index number of the newly created DataGrid row is by using:

e.Item.ItemIndex.

Did I just break my promise to stick to "kev speak" by mentioning Event Delegates? Never mind I'm sure it did not hurt too much.

Next is the your code here section, I will leave what goes in this section for you to decide, I'm sure you will work out what's meant to be in this section given time to ponder!

OnClick="Button1_Click"

 

Previous: What order do events get executed? Next: Some simple examples
 
Web Design Telephone Tel: 01738 444240  Web Design Fax Fax: 01738 560336  Web Design Email E-mail: webxel-dw.co.uk
© WebXeL.com Ltd
FREE & Commercial Dreamweaver MX Extensions from WebXeL.com Ltd