Reputation: 22065
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?
Upvotes: 10
Views: 23787
Reputation: 96571
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.
Upvotes: 31
Reputation: 2656
If one wants to not use the way as described by M4N but through code:
In the PageName.aspx.cs;
private void InitializeComponent()
{
// this.LifeCycle += .. // Use intellisense to see alternatives easily
this.PreRender += new System.EventHandler(this.EventFunctionName);
}
then in the same file add:
private void EventFunctionName(object sender, EventArgs e)
{
// Code..
}
UPDATE (from comment by Sahuagin): This won't generate an event handler with the appropriate name. The event handler must be named, for example, Page_Load. This will name it after your class rather than after Page, and so it won't actually be hooked up to your page
Upvotes: 0
Reputation: 1
TreeScheme.Nodes[0].ChildNodes[0].Checked=true;
treeviewid.node[0].childnodes[0].checked=true;
This will set the child node checked true in page load event of page
happy coding
Upvotes: -1
Reputation: 1
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.
Upvotes: 0
Reputation: 26956
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.
Upvotes: 4
Reputation: 41568
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.
Upvotes: 3