How to add event to Web Form from the vs.net designer

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hi there,

I know that when i double click a web form I'm taking to the page_load
event. However, I want to create an unload event by I don't know how to
create it from the vs.net designer. Does anybody know how to create a page
unload event from the vs.net designer?



Many thanks
 
You can use the designer to configure events for the controls on a page
besides the default event you get by double-clicking the control by clicking
the events button on the Properties window for the control and then
double-clicking or typing in the field for the desired event. Unfortunately,
the Page itself does not have this option (see MSDN
http://msdn2.microsoft.com/en-us/library/6w2tb12s(VS.80).aspx).

So, you'll have to create it in code.

For C#, if you have AutoEventWireup="true" in your <%@ Page %> declaration
in the markup, you can put the following in your code to handle the Page
unload event:

protected void Page_UnLoad(object sender, EventArgs e)
{
//Your page unload code here
}

For VB, you can use the drop down box in the upper left corner of the code
window and select "(Page events)" and then select the event you want to
handle from the drop down box in the upper right corner (in this case the
unload event). Visual Studio will then create the procedure for you.

Hope that helps.
Jason
 
Back
Top