472,338 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,338 software developers and data experts.

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 9494
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Prasad | last post by:
We are invoking a SQL DTS component (lets call it Comp1) built by us in another component (Comp2).Comp1 was built by creating the DTS package using...
1
by: Robert Scheer | last post by:
Hi. Debugging one of my pages I noticed that everytime I call the page, the first event to run is Page_Load and after it the Page_Unload. If I...
19
by: Heidi Hundla | last post by:
Hi ! I have a Wep App in C#. Page_Unload fires after Page_Load, and it seems totally unreasonable when you want to use this event when you...
4
by: Larry Morris | last post by:
The following code, pasted into a web form with a link button on it, will cause the page_unload event to fire twice. If I remove the...
0
by: chefo | last post by:
Well, the subject describes my problem quite well :-) Here is some additional information. I use a common base class for all the pages in my...
0
by: JeffM | last post by:
This seems odd, but it appears that the Page_Unload event is fired twice on a Response.Redirect or a Server.Transfer. The output below...
7
by: Cenk | last post by:
Hi, After converting my projects to ASP.Net 2.0 I have seen a problem with Page_unload. İn framework 1.1 page_unload event fires when you are...
2
by: RAM | last post by:
Hello, I am learning .NET 2.0 and I have written simple application with Default.aspx page and logging in Logon.aspx/Logon.aspx.cs. After...
5
by: =?Utf-8?B?Um9sYW5kcGlzaA==?= | last post by:
Hi there, I'm using Web Developer Express 2005 in my ASP.NET learning. I tried creating a simple aspx page using "code-behind" approach. I noticed...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.