{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Creating event handlers in a hurry
Summary
It is a well known practice to double click on a control in the design window to create the signature for the standard event handler for that control in the code window. But when it is time to create a different event handler for that control, you might have guessed the parameters or copy pasted from somewhere else. There is a quicker way.
 
Table of Contents

Event Handlers for different events

Figure 1. Events in the Properties Window

 

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

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.
Bookmark and Share This

More Articles With Similar Tags
icon-sqlite-source-new-project-wizard.jpg
This article shows how to set up a project and compile the SQLite shell and database engine source code with Visual Studio. Screenshots included.
icon-vs2008-features.jpg
This article has notes and some screenshots of installing Visual Studio 2008 RTM version.
icon-android-winmobile-dev-vs2008.jpg
This article discusses and compares the development environments and technologies (Visual Studio, Eclipse, C#, Java, .Net Framework, Android SDK, etc.) used for developing Windows Mobile and Android applications.
icon-vs2008-first-start.jpg
These are my notes and observations on Visual Studio 2008 Beta 2. This article focuses on my installation of VS 2008 Beta 2 on a Windows Vista Ultimate machine. This article also has some screenshots from the installation.
icon-vss-settings-for-ind-dev.jpg
This article looks at the integration of Visual SourceSafe and Visual Studio. Some settings pertaining to the independent developer in the source control are also explored.
About  Contact  Privacy Policy  Site Map