Auto-stub ASP.NET Page Event Handlers

For whatever reason, Visual Studio does not offer an intuitive procedure for stubbing out an .aspx page’s event handlers.

The easiest procedure that I can come up with is:

  1. View the .aspx page in Code View
  2. Within the page’s class, create a method using the override modifier. Visual Studio’s Intellisense will display the list of the classes members that can be overridden.

Example:
Create a method using the override modifier, then select the method, event, property, or indexer that you would like to override.

Visual Studio will stub out the method for you calling the base.

Note how the overridden event handler in the above example is named OnPreRender(). It’s worth noting that this method is the same as the Page_PreRender() event handler.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s