How do we use Events?
Steps to use events
Now that we know what events are, it is time to learn how we can use them in our applications. Using an event generally means writing the event handler for that event. Event handlers are written using a programming language like C# or VB.NET and the code will depend on what we want to do when the event takes place. However, we should know how to add the event to our page.
The easiest way to add an event to the page is to double click the control for which we want to add the event. For example, if we double click on a button control, its click event handler structure will be displayed by the IDE. If we are using the inline model, it will be located in the source view of the page, inside the <script>...</script> tag. If we are using the code-behind model, the event handler structure will be inside the code-behind source file. Now all we need to do is to write the actual code inside the event handler structure.
Double clicking on a control shows the event handler structure for the default event of the control. If we want to use some other event, here is the process:
1. Select the control on the page by clicking on it.
2. Open the properties window. Generally, it displays the properties of the control. However, if we click on the Event button at the top, a list of available events for the control is displayed.
3. Double click in the empty cell next to the event name that we want to program.
If we are using the inline model, the event handler structure will be displayed in the source view of the page. On the other hand, if we are using the code-behind model, the event handler structure will be displayed in the source code file. Now we can write the actual code for the event handler.
In this chapter, we have covered one major aspect of application development - writing code and handling events. In the next chapter, we will discuss more about coding and understand the concepts of object-oriented programming.

