If you added, say, a button to the aspx page and then double-clicked on it in the Design window, Visual Studio will create an event handler called Button1_Click (assuming the name of the button is still Button1) in the code window. In this handler you will write the code to handle that click.
And most likely that’s the only event handler you will write for that control. Similarly if you added TextBox, then when you double-click on it, a handler called TextButton1_TextChanged will be created for you. While these standard controls have other events like Init, Load, PreRender, etc., you will most likely be sticking with just the primary/widely handled event like Click, TextChanged, etc.
Event Handlers for different events
However, when you use more substantive controls like GridView, you will have a whole bunch events at your disposal. If you double-click on a GridView control in the Design Window, Visual Studio will create GridView1_SelectedIndexChanged event handler with the correct parameters (object and EventArgs).
GridView has a whole bunch of other events that you might use from time to time; for example, RowDeleted, RowDeleting, PageIndexChanged, PageIndexChanging, etc. Some of them have different Event Argument parameter than the standard EventArgs. Double-clicking on the control in the Design Window will take you to the standard SelectedIndexChanged event handler, not to one of these other event handlers.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
Visual Studio provides a convinient way to creating any of the supported event handlers for a given control. In fact, it takes just a double-click. Following picture shows where to do that double-click:
Figure 1. Events in the Properties Window
- Go to the Properties Window for that control (right-click on the control in the Design Window)
- Click on the Events toolbar at the top of the Properties window. Now you will see all the supported Events for that Control.
- Now double-click in the value cell of the event you wish to create the EventHandler for. For example, if you double-click in the value cell of PageIndexChanging event, you will have GridView_PageIndexChanging event handler created in the code window.