Solved

Where are the event handlers in VS 2008

Posted on 2008-10-27
1
1,588 Views
Last Modified: 2013-12-17
I have a project in VS 2008 that is using Master Pages.  I want to add an event handler to the Page_PreRender event, but I don't see it listed under any of the control properties.  If I select a panel control, it has a Panel_PreRender event, but there is no "Page" control to select.  The top item in the list is DOCUMENT, which does not have any events.  Thanks!
0
Comment
Question by:jvalescu
1 Comment
 
LVL 16

Accepted Solution

by:
ororiole earned 500 total points
ID: 22819460
Visual studio doesn't list the events for pages. I dont remember Visual Studio 2005 doing it either. And if you are looking for them under a control, you won't find them there. Controls expose their events, they have never exposed the Page events.

But here is what you do. You have two options.
1. In your <%@ Page directive on your markup page, add AutoEventWireup="true". Then in your code behind you type in your page eventhanders using the name "Page" followed by "_<eventname>" just like you did above with Page_PreRender. So you can also have protected void Page_Load(object sender, EventArgs e), protected void Page_Init(object sender, EventArgs e), etc. The runtime will register the eventhandler with the event for you as long as you follow the naming convention.

2. You wire them up yourself and you can use any name you want, but by convention you should still use the naming pattern. So in the constructor for your page, you can enter:
Page.Load += Page_Load, Page.PreRender += SomeOtherEventHandlerIfYouWant. In this case, set AutoEventWireup="false" otherwise you will will register it twice and it will fire twice.

There are other ways but they get more obscure.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question