views:

929

answers:

5

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?

A: 

A list of Page events can be found here.

Matthew Jones
+5  A: 
  • 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.

M4N
A: 

as a shortcut to see what's available, you could always just type "Page." and then take a look a the list in intellisense. You could then pick one, hit +=Tab Tab to have it generate the stub for you. once the stub is created, you'd have to delete the "Page.event+=" line wherever you created it. Kind of a hokey workaround, but can work pretty quick once you get the hang of it.

Scott Ivey
+1  A: 

With the invaluable ReSharper installed (might work without) I can just type:

override

and when I hit space IntelliSence pops up with a list of all the events that I can override such as OnInit, OnPreRender, etc.

Zhaph - Ben Duguid
A: 

In the source code window, from the object list combo box, select the desired control (page). Then from the event list combo box that is to the right of the previous object list combo box select the desired event. Visual studio will create the event handler for you.

chongo