Solved

Where are the event handlers in VS 2008

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

805 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