Invoking Page_Unload from a C# code behind module

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm just trying to manually add a page_unload function in my code-behind
module, but with no success. Can anyone help me with the correct syntax to
add the function to my code?

I've tried the following already with no joy:

protected void Page_Unload(object sender, System.EventArgs e)
{
Session.Add("SES_CURRENT_SRQ", 34);
}

public void Page_Unload(object sender, System.EventArgs e)
{
Session.Add("SES_CURRENT_SRQ", 34);
}

void Page_Unload(object sender, System.EventArgs e)
{
Session.Add("SES_CURRENT_SRQ", 34);
}

Thanks
 
I'm just trying to manually add a page_unload function in my code-behind
module, but with no success. Can anyone help me with the correct syntax to
add the function to my code?
Your methods are correct, but you're probably missing the code to create
an event handler for the Unload event. If you're developing with
Visual Studio .NET the code to do this is located in the
InitializeComponent method. This method is called from the overridden
OnInit method. These methods are found within the "Designer generated
code..." region.

To set up an Unload event handler in your code add the following lines:
this.Unload += new System.EventHandler(this.Page_Unload);

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Yup - that's the ticket. I guess I can still blame the New Year for not
thinking of that.

Thanks.
 
Andrew Vickers said:
Hi,
I'm just trying to manually add a page_unload function in my code-behind
module, but with no success. Can anyone help me with the correct syntax
to
add the function to my code?

I've tried the following already with no joy:

protected void Page_Unload(object sender, System.EventArgs e)
{
Session.Add("SES_CURRENT_SRQ", 34);
}

public void Page_Unload(object sender, System.EventArgs e)
{
Session.Add("SES_CURRENT_SRQ", 34);
}

void Page_Unload(object sender, System.EventArgs e)
{
Session.Add("SES_CURRENT_SRQ", 34);
}

Just adding it won't help. You will have to connect it. In the Page_Init
method, you'll need to add:

this.Unload += new EventHandler(Page_Unload);


Alternatively, you can override the OnUnload method:

protected override void OnUnload(EventArgs e)
{
// Session.Add
base.OnUnload(e);
}

John Saunders
 
Back
Top