JavaScript Editor Javascript validator     Javascripts

Main Page


Previous Section Next Section

3.1 Event Model

The two models of program execution (which are not necessarily mutually exclusive) are linear and event-driven.

Linear programs move in a linear fashion, from step 1 to step 2 and so on, to the end of all the steps. Flow control structures within the code (such as loops, if statements, or function or subroutine calls) may redirect the flow of the program, but essentially, once program execution begins, it runs its course unaffected by anything the user or system may do. Prior to the advent of GUI environments, most computer programs were linear.

In contrast, event-driven programming responds to events. An event is generated (or raised) when "something happens," such as the user pressing a button. Often, events are generated by user action, but events can also be generated by the system starting or finishing work. For example, the system might raise an event when a file that you open for reading has been read into memory or when your battery's power is running low.

Windows is an event-driven program. The operating system is relatively quiescent until it detects an event such as the user clicking the mouse on a button. The click raises an event, which must be handled. The method that responds to the event is called the event handler. When the event is raised, the event handler, if one exists, is automatically executed by Windows.

In ASP.NET, objects may raise events and may have assigned event handlers. For example, a button may raise the Click event and may have an OnClick method that handles the event.

The event handler name is formed by prepending the word "On" to the event name, so in the case of a Click event, the event handler is called OnClick. Table 3-1 lists some of the more commonly used events and the names of their event handlers.

Table 3-1. Common events and their event handler names

Event name

Event handler name

Applies to

BubbleEvent

OnBubbleEvent

All controls

CheckedChanged

OnCheckedChanged

CheckBox

Click

OnClick

Button, LinkButton, ImageButton

DataBinding

OnDataBinding

All controls

Init

OnInit

All controls

ItemCreated

OnItemCreated

Repeater

ItemDataBound

OnItemDataBound

Repeater

Load

OnLoad

All controls

PreRender

OnPreRender

All controls

SelectedIndexChanged

OnSelectedIndexChanged

DataGrid, DataList, CheckBoxList, DropDownList, ListBox, RadioButtonList

TextChanged

OnTextChanged

TextBox

Unload

OnUnload

All controls

    Previous Section Next Section


    JavaScript Editor Javascript validator     Javascripts 
    R7



    ©