469,578 Members | 1,742 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

Invoking Page_Unload from a C# code behind module

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
3 9393
> 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
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
"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.

Similar topics

1 post views Thread by Robert Scheer | last post: by
19 posts views Thread by Heidi Hundla | last post: by
4 posts views Thread by Larry Morris | last post: by
reply views Thread by chefo | last post: by
7 posts views Thread by Cenk | last post: by
5 posts views Thread by =?Utf-8?B?Um9sYW5kcGlzaA==?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.