How do I add Page Events for ASP.NET in Visual Studio 2008

Chet picture Chet · Jun 25, 2009 · Viewed 22.8k times · Source

This is a bit of a Visual Studio question. I feel with all the helpful Intellisense there should be something to assist but I can't seem to find it.

I made a page with a codebehind in ASP.NET C# in VS2008 and it autogenerates a PageLoad event method, of course. Well, what if I want to add methods for more events besides PageLoad? I would think there would be some list on the Foo.aspx page of possible method event handlers to add. Aren't there more maybe like PageInit, PageDispose, (or equiv) etc...? Where can I find these?

EDIT - I can of course look up the method names in the api. I'm looking for a handy shortcut to add these in Visual Studio. If it generates one, can't it make others?

Answer

M4N picture M4N · Jun 25, 2009
  • In the solution explorer, right click the page and select "View component designer" from the context menu
  • open the properties panel/window (press F4)
  • now click the yellow arrow/flash icon and you will see a list of all page events
  • double-click the event for which you want to add a handler

I'm pretty sure there was another way (starting from the designer view), but I can't reproduce it.

I usually do not use the page event handlers, instead I override the corresponding methods (e.g. OnLoad instead of Page_Load). To implement one of these overrides, you can simply type "override" in the code-behind and press space to get a list of methods that you can override.