What are Events?
Defining function and uses of events
So far, we have seen that when the user interacts with the controls on the page, some actions occur. For example, if the user clicks on a button, a code specifies what should happen. These actions are known as Events. When an event takes place, we call it event firing or event raising. Therefore, when the user clicks a button, the click event of the button is fired.
The code that executes (runs) when an event is fired is known as event handler. We can write event handlers for different controls on the page. Then, when the user interacts with a control and fires an event, the event handler for that event of the control will run.
Some commonly used Events
|
Control |
Event |
Use |
|
Button |
Click |
When the button is clicked. |
|
DropDownList, ListBox |
SelectedIndexChanged |
When the selection in the list changes. |
|
CheckBox, RadioButton |
CheckChanged |
When the Checked/Un-checked status of the control changes. |
|
TextBox, ListBox, DropDownList |
TextChanged |
When the text in the control is changed. |
Apart from these events for the commonly used controls, we can use events for some advanced controls like the Login controls and Data controls. We will learn about them in the coming chapters.