|
 |
aspx thread: Page_Unload will not fire
Message #1 by "Eirik Hommeren" <hommeren@h...> on Wed, 26 Sep 2001 09:57:31
|
|
I am coding several aspx-pages using code-behind and c# (Beta2). My
Page_Unload-method will not fire when leaving a page. Any Suggestions?
private void Page_Unload(object sender, System.EventArgs e)
{
// some code
}
Eirik
Message #2 by "Mitch Denny" <mitch.denny@w...> on Wed, 26 Sep 2001 20:00:18 +1000
|
|
Eirik,
Are you wiring up the event handler to the event? In the
codebehind there somewhere you should see a line similar
to the following:
this.Unload += new EventHandler(Page_Load);
If you don't you need to set it up. A good place to do
it is in the Page.Init event handler which is created
by default (assuming that you are using VS.NET).
Hope this helps. If the problem persists post your
code to the list (in the message, not as an attachment).
----------------------------------------
- Mitch Denny
> -----Original Message-----
> From: Eirik Hommeren [mailto:hommeren@h...]
> Sent: Wednesday, 26 September 2001 9:58 AM
> To: ASP+
> Subject: [aspx] Page_Unload will not fire
>
>
> I am coding several aspx-pages using code-behind and c# (Beta2). My
> Page_Unload-method will not fire when leaving a page. Any Suggestions?
>
> private void Page_Unload(object sender, System.EventArgs e)
> {
> // some code
> }
>
> Eirik
Message #3 by "Eirik Hommeren" <hommeren@h...> on Wed, 26 Sep 2001 12:43:55
|
|
Thanks!!!!
Yes, I'am closer; the Page_Unload gets fired, not on page-unload, but
direct after the Page_Load method: Here's my code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.ImageButton
ImageButton1;
protected System.Web.UI.WebControls.CheckBox CheckBox1;
public WebForm2()
{
Page.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
string test = "nada";
if (Session["test"] == null)
Session["test"] = "first";
test = Session["test"].ToString();
TextBox1.Text = Session["test"].ToString();
}
private void Page_UnLoad(object sender, System.EventArgs e)
{
Session["test"] = "unload has been fired";
}
private void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET
Web Form Designer.
//
InitializeComponent();
}
#region Web Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler
(this.Page_Load);
this.Unload += new System.EventHandler
(this.Page_UnLoad);
}
#endregion
}
}
What am I doing wrong here?
> Eirik,
>
> Are you wiring up the event handler to the event? In the
> codebehind there somewhere you should see a line similar
> to the following:
>
> this.Unload += new EventHandler(Page_Load);
>
> If you don't you need to set it up. A good place to do
> it is in the Page.Init event handler which is created
> by default (assuming that you are using VS.NET).
>
> Hope this helps. If the problem persists post your
> code to the list (in the message, not as an attachment).
>
> ----------------------------------------
> - Mitch Denny
|
|
 |