Invoking Page_Unload from a C# code behind module

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
 
G

Guest

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/
 
G

Guest

Yup - that's the ticket. I guess I can still blame the New Year for not
thinking of that.

Thanks.
 
J

John Saunders

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
 
Joined
Dec 3, 2007
Messages
1
Reaction score
0
John Saunders said:
"Andrew Vickers" <[email protected]> wrote in message
news:[email protected]...
> 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

So far I have this in the code behind:
Code:
protected void Page_Init(object sender, EventArgs e)
    {
        this.Unload += new EventHandler(QuickQuote_Unload);
    }
protected void QuickQuote_Unload(object sender, EventArgs e)
    {
  (Stored Procedure)
    }

The SP fires and loads info the to DB, but it only does it on page load not on page unload.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top