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

So what's cool about events?

Everything!

But you're probably hoping for a more detailed explanation right? Oh well here goes.

Traditionally web pages with server side code are executed in a linier flow. What this means is that each line is evaluated and executed from the top to the bottom, line 1 of the code is executed before line 3 and line 3 is executed before line 25. When you need to control whether certain lines of code should be executed you're required to perform some kind of conditional check within the code such as using if and else blocks or select case statements.

A prime example of this is a page with multiple buttons for submitting a form and the page needs to know what button was pressed, using previous version of ASP and many other server side programming languages it's necessary to check the request form values to determine which button was clicked to submit the form and then use conditional checks within the code to execute the section of code specific to that button.

ASP.NET does things a little differently, actually it does things a lot differently, and the previously mentioned buttons example can be achieved using ASP.NET with no conditional checks required, you can attach an event procedure to each button that only contains the code you want executed for that button, below is a simple example of a button click event procedure:

C#
<script runat="server">
    void Button1_Click(object sender, System.EventArgs e)
    {
        Response.Write("You clicked the button!");
    }
</script>

VB
<script runat="server">
    Sub Button1_Click(sender As Object, e As System.EventArgs)
        Response.Write("You clicked the button!")
    End Sub
</script>

Button control tag:

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

We will dissect and explain each part of this code a little later in the article, hopefully you can by now see how cool events are, if not keep reading and you will.

 

Previous: What is an event? Next: What order do events get executed?
 
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