Solved

Where are the event handlers in VS 2008

Posted on 2008-10-27
1
1,586 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

947 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now