Solved

Where are the event handlers in VS 2008

Posted on 2008-10-27
1
1,585 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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

16 Experts available now in Live!

Get 1:1 Help Now