By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

Invoking Page_Unload from a C# code behind module

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> 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/
Nov 19 '05 #2

P: n/a
Yup - that's the ticket. I guess I can still blame the New Year for not
thinking of that.

Thanks.

"Anders Norås [MCAD]" wrote:
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/

Nov 19 '05 #3

P: n/a
"Andrew Vickers" <10***********@noemail.nospam> wrote in message
news:24**********************************@microsof t.com...
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
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.