Page.UnLoad Event

I'm trying to make my webform to some final processing when the user exits (closes the browser window). What I did is to declare an eventhandler for Page.UnLoad and when that was fired my Page_hasunLoaded(Object sender, EventArgs e) method was supposed do the processing.

My "application" (simplified) consist of a Login page which (if login&password correct) redirects me to the page I am talking about. But exactly when the Login page redirects me THEN the event gets fired. Nothing happens when I close the browser window. I don't understand how Page.unLoad gets fired when I'm loading up the page.
Here's my code:
dbComm dbComm;
protected System.Web.UI.WebControls.DropDownList stigList1;
protected System.Web.UI.WebControls.DropDownList stigList2;
protected System.Web.UI.WebControls.DropDownList stigList3;
protected System.Web.UI.WebControls.DropDownList stigList4;
protected System.Web.UI.WebControls.DropDownList stigList5;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid QuestionsGrid;

private void Page_Load(object sender, System.EventArgs e)
this.Unload += new System.EventHandler(this.Page_unLoaded);
dbComm = new dbComm();
catch (System.Data.OleDb.OleDbException err)
Response.Redirect( "villa.aspx?err=" + err.Message.ToString() );



stigList1.SelectedIndex = dbComm.getStig(1, (int)Session["userID"]);
stigList2.SelectedIndex = dbComm.getStig(2, (int)Session["userID"]);
stigList3.SelectedIndex = dbComm.getStig(3, (int)Session["userID"]);
stigList4.SelectedIndex = dbComm.getStig(4, (int)Session["userID"]);
stigList5.SelectedIndex = dbComm.getStig(5, (int)Session["userID"]);

private void loadQuestions()

QuestionsGrid.DataSource = dbComm.getTable("Questions");
QuestionsGrid.DataKeyField = "QuestionID";
TemplateColumn dgc = new TemplateColumn();

dgc.HeaderText = "Stig:";

protected void QuestionsGrid_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e)
int preQuestionID = (QuestionsGrid.CurrentPageIndex * 5); int userID = (int)Session["userID"];

QuestionsGrid.CurrentPageIndex = e.NewPageIndex;
Label1.Text = QuestionsGrid.CurrentPageIndex.ToString();

if(QuestionsGrid.CurrentPageIndex != 26)
dbComm.updateAnswersTable(preQuestionID + 1, userID, Convert.ToInt16(stigList1.SelectedItem.Value));
dbComm.updateAnswersTable(preQuestionID + 2, userID, Convert.ToInt16(stigList2.SelectedItem.Value));
dbComm.updateAnswersTable(preQuestionID + 3, userID, Convert.ToInt16(stigList3.SelectedItem.Value));
dbComm.updateAnswersTable(preQuestionID + 4, userID, Convert.ToInt16(stigList4.SelectedItem.Value));
dbComm.updateAnswersTable(preQuestionID + 5, userID, Convert.ToInt16(stigList5.SelectedItem.Value));
preQuestionID = (QuestionsGrid.CurrentPageIndex * 5);
stigList1.SelectedIndex = dbComm.getStig(preQuestionID + 1, userID);
stigList2.SelectedIndex = dbComm.getStig(preQuestionID + 2, userID);
stigList3.SelectedIndex = dbComm.getStig(preQuestionID + 3, userID);
stigList4.SelectedIndex = dbComm.getStig(preQuestionID + 4, userID);
stigList5.SelectedIndex = dbComm.getStig(preQuestionID + 5, userID);
stigList3.Visible = false;
stigList4.Visible = false;
stigList5.Visible = false;

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
// CODEGEN: This call is required by the ASP.NET Web Form Designer.

/// <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);
// override protected void OnUnload(EventArgs e)
// {
// dbComm.updateAnswersTable(1,2,4);
// }

protected void Page_unLoaded(object sender, EventArgs e)


As you can see I also tried overriding OnUnload which did exactly the same thing.
Does anyone have any idea how I can implement this?
PS. For your information, the reason I need this is because I want the choices made with the dropdownlist (which get inserted into my database whenever the user goes to another DataGrid Page) to be inserted too, if he closes the browser window. Then when he returns he will see everything exactly as he left it.
7/23/2002 7:33:01 PM 93655 articles. 5 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 14

The Page_Unload event is a little confusing to the uninitiated.  The key to understanding the behavior you're seeing is that the Page_Unload event handler executes _after_ the page has already rendered a response, but _before_ the instance of the Page's class on the server has been terminated.  In your case, the Unload event fires after the Redirect has been called, but this is exactly when the event is meant to fire.  

The server has absolutely no idea when the user is closing her browser window, hence we have no event that does quite what you're looking for. If you want to catch the new selections in a DropDownList every time the user changes it, you should set AutoPostBack to True on the DropDownList control in which you are interested and use its SelectedIndexChanged event to read the new values.
I hope this helps.
7/23/2002 8:39:55 PM
Could I not use a "Session.end" event and making the database insertion start when that event happens. I would then put the last few user selections into a Session object (an array for instance) and when the Session dies (which should be when the user is no longer online) it writes the last selections to the database. How would I implement that? Use Global.asax?
7/24/2002 12:59:51 PM
Hi halli,

there is no need to make changes in the global.asax for that, you may just set the autopostback from the dropdown list to true and handle the result when it comes.
wish this helps
Best Regards,

Thomas Crown.

This posting is provided "AS IS" with no warranties.

"If Debugging is harder than writing a program and your code is as good as you can possibly make

it, then by definition you're not smart enough to debug it."
4/1/2004 2:45:25 AM

Similar Artilces:

Can my web page with a form submit to other web pages forms?
I was wondering if I created an aspx page that had a form on it that I could use the submit button to submit this form's contents to other web pages forms(servers accepting those form's data). I am thinking this would be a great way to update data on particular web pages without having to actually visit those similar web pages. Any ideas, examples would be much appreciated. Thanks in advance.  Yes you can.  It's called Cross Page Posting: might ...

How to fire events in other web form from other web form ?
Suppose that I have A and B web form. I want to trigger B web form's Page_Load event from A web form. How can I do that ? Thanks in advanced WilbertWilbert Bujn Create a public method in B that call the load method : public void Load(object sender, System.EventArgs e) { Page_Load(sender, e) ; } In the page_load of A, instanciate a B object and then call the function B myB = new B() ; myB.Load() ; Quicky Thank you quicky, it works fine. WilbertWilbert Bujn...

Could PB .NET Web Form POST security Information to others web page??
This is a multi-part message in MIME format. ------=_NextPart_000_00F9_01C9C4D5.8FB45C90 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: quoted-printable Hi,=20 Have anyone came across the requesion to POST security informations from = PB .NET web form web page to other web site?? I have tried many datys, Could any kind man give me some suggessions?? thanks & Best regards Leon ------=_NextPart_000_00F9_01C9C4D5.8FB45C90 Content-Type: text/html; charset="big5" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML P...

how to open a web page in form of a popup web page
Hello, I have two web pages, let say. Page A : With a Button on it. PAge B: with some info. Now I need to: When I click on the Button of page A.Page B must open in a pop up window.  I can do this but problem is this when I clicked on the button for first time it does not show me any thing and when I clicked on the button for second time then It shows me Page B .My code is as follow:  1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!this.Page.IsPostBack) 4 { 5 6 } 7 else 8...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

Open web page in IE and populate fields on the form from my web form
To the dot net Knights.  Many humble thanks in advance from a dot net surf. We have an vb application that opens multiple instances of IE object, each to different web pages.  It then takes information from the current record in the app, populates fields on each of the web pages, and them submits the forms.  We are then able to look at the resulting web pages and quickly get the info we're looking for.This prevents us from having to manually navigate to each web site, enter the same information and then wait for the page to open.  If there is a captcha control, we only need to enter it and then manually hit submit. We are moving our systems to the web.  My question:  Is there a way to do this from a web form?The follow-up questions would be, where do I go to find out how to open multiple tabs in IE 7 to do the same thing?Thank you in advance,David C...

Creating a Scheduled Event thru .NET web page?
Does anyone know if it is possible to make an administrative page that could create a scheduled event on a web server machine? or even better yet if there is a way to make a .NET page run on a certain timeframe without using Scheduled Events on the web server? I have a batch script that I would like to give users the ability to change the time of when it runs or create multiple times in which it could run. Any insight would be appreciated... Thanks! vc ASP.NET is not intended for running scheduled tasks. It's really setup to response to browser requests and use the browser...

How to add event to Web Form from the designer
 Hi there, I know that when i double click a web form I'm taking to the page_load event.  However, I want to create an unload event by I don't know how to create it from the designer.  Does anybody know how to create a page unload event from the designer? Many thanks  Page events are not exposed in the design view. If you are using VB, you should be able to use dropdowns on top of the code editor -> select Page in the left one and the designed event in the right one and editor will generate the code. Unfortunately, C# editor does not p...

form or page event and child forms
I need to know which event I can write code for when a user closes a form or window without submitting so that I can delete a file uploaded with the file upload control.  In other words, I need to cancel a file upload if a form is not actually submitted. Also, my file upload control is actually a control within a fileupload.ascx .  How do I access any objects like controls in a fileupload.ascx from the parent form? thanks MiltonregardsMilton Hi, The file in the file upload control won't be uploaded until the user submit the form, so you don't have to clear the file when ...

Accessing a method within a class VB.NET from a Web Form page.
 I got the following class within my App_Code folder under a file called DataAccess.vb: Namespace CircaComArtAccess Public Class ComArtData Private _connstr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ESQLConn").ConnectionString() Public Sub ComArtGrid(ByVal procedurename As String, _ ByVal parameters() As SqlParameter, _ ByVal gridname As ComponentArt.Web.UI.Grid, _ ByVal e As ComponentArt.Web.UI.CallBackEventArgs, _ Optional ByVal commandtype As CommandType = 1 _ ) Dim SQLConn As SqlConnection...

.NET 1.1 Web Form
I am scratching my head trying to figure out why my events button (Lighting Bolt) is not displaying when I select buttons in Visual Studio 2003.  Has anybody had this happen before? I am tired into Visual Source Safe and wonder if that has anything to do with it?Moojjoo Õ¿Õ http://www.mmwebs.com Ummm>>>   That is the difference between C# and VB.NET.  VB.NET does not display the Lightning Bolt under properties in VS 2003.Moojjoo Õ¿Õ http://www.mmwebs.com

A page can have only one server-side Form tag
I have a web user control in my web page.  The user control (ascx) consist of a text box and button. The web page consist of text boxes and buttons also.  Both pages have form tags with runat=server.  When I run the web page it comes up with the error "A page can have only one server-side Form tag." Both the user control and web page need the form tag with runat=server.  Is there a way I can code these pages where there won't be a conflict between the web user control and the web page? Thanks   JohnMo wrote:Both the user control and web page need the form tag wit...

In large web page, every page_load event makes position to page beginning.To go bottom I have to use scrool but I want to position on any location automatically after page_load event
In large web page, every Page_Load event makes position to page beginning.To go bottom I have to use scrool but I want to position on any location automatically after Page_Load event. for exemple: I have a check box named "C8" at the bottom of the web page. Normally I must scrool to bottom to see this control. I want to see this control without scrooling after every Page_Load event. How can I do this, (with c#) Thanks. The easiest way is to use SmartNavigation. It only works with modern IE browsers (5.5+). Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you!...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Keeping the web form on top of all other forms/pages
Hi all,         I need to know how to keep my web page always on top...atleast let me know weather its possible...I dont want to  give focus to page when focus is lost. I dont want to intrupt any other application on the machine ( as focus does )...but yet let it float on the top ( even in disabled mode if possible)I kind of want to do something like setting the z-order to 1... Is there any api 'focus' uses to achieve this ( bring the page frount ).? Thanks in advance,Suman No, thankfully you can't do this from a web page - imagin...

How to convert web form(web page) to a word document
Hi Guys.Can any one give me a hint on how to  convert a web form (a web page) to a word document.Thank You...

How do you incorporate a web page in a web form without IFrame
I would like to display a web page in my web form, but don't want to use frames or I frames. Can it be done with a label? If not then any suggestions and code would be appreciated. Thanks Please describe in more detail what you are trying to achieve. Frames and IFrames are for the purpose of rendering >1 html page in a single browser window. AFAIK there is no other way to achieve this purpose, but maybe you are trying to describe a different purpose? Basically it's a search page. The search term is picked up from a text box and then a URL is called. The URL is fed with the s...

.Net Web Form & Web Service Deployment
Hi all I have written some test web services and some web form applications and deployed them to my IIS. That's fine but I now want to deploy them to my real IIS server. I have created an msi for each but the problem is I seem to only be able to deploy to the default web site. Our default web site is turned off and instead we use several other sites. Does anybody happen to if Powerbuilder 11 supports non default web sites? If not do I need to hack the msi and if so can anybody suggest a suitable tool. I have Orca but it's not very friendly. Unless of course I knew exactly what data I need to change in the msi. Thanks Graeme ---== Posted via the PFCGuide Web Newsreader ==--- There are a number of tools out there that will allow you to edit the MSI file. You might look at: "Graeme Cooke" <> wrote in message news:4669b57f$1@forums-1-dub... > Hi all > > I have written some test web services and some web form applications and > deployed them to my IIS. That's fine but I now want to deploy them to my > real > IIS server. I have created an msi for each but the problem is I seem to > only be > able to deploy to the default web site. Our default web site is turned off > and > instead we use several other sites. > >...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/browser capabilities check out BrowserCapabilities (usage: Request.Browser) and MobileCapabilities (usage: MobileCapabilities mc = (MobileCapabilities)Request.Browser) classes.Gunnar Peipman-- General Protection Fault-- Illegal Page Fault-- Not My Fault...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Sharepoint help! Error msg : "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe"
hihi, I have set up a testing virtual server on my local machine. I installed win server 2003, wss 2.0, sql server 2000, and visual studio .net 2003. i tried to create a project in C# but when i build it and import the web part (.dwp) into the page, there is this error msg "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe"  I seached most of the sites and they informed that the problem lies in the safe control in web.config i enter the safe control in web.config but i does not know where to put ...

Form authentication for only 1 page in a web site of 5 pages.
Hi, I am using a login control / form authentication / membership provider (ASP.NET 2.0) to authenticate to my Active Directory. There are 5 pages in my web site, I want to put only one page under the control of form authentication and not the rest of them. Please guide on how I can achieve this. Currently access to any page on my site redirects to the login page. Regards & thanks Kapil x Hello Kapil my friend, Excuse my previous post.  Something wrong with my connection.  You will have the following within your web.config: - <system.web>  &...

web page opened as dialog does not fire page load event
All,I use the following code to open a web page  as a dialog formMe.btnAddInstruction.Attributes.Add("onclick", "var strReturn; strReturn = window.showModalDialog('AddInstruction.aspx',null,'toolbar:no;menubar:no;status:no;dialogWidth:350px;dialogHeight:350px;dialogHide:true;help:no;scroll:no');")The web page which is being opened has a page load event which populates combo boxes on the web page. However this page load event doesn't fire when the page is opened as a dialog but instead when the page is closed. Now I have a feeling its because the javascript used to open the web pa...

Debugging exception when loading a web page in the Web Forms Designer
In a project at work I have inherited, I am getting an exception when loading an .aspx page in the Web Forms designer. The project was originally created with VS .NET 2002 and I am upgrading it to VS .NET 2003. It appears that the Web Forms designer actually attempts to instantiating an instance of the codebehind class in order to bring ou the Web Forms designer page. Why does it do this ?The codebehind class inherits from another class, which inherits from System.Web.UI.Page. It is in this other class in which the exception is occurring.Is there any way I can debug this so that I can find o...

Web resources about - Page.UnLoad Event -

Facebook CAO Jas Athwal Unloads Some Shares
... its initial public offering tag of $38 per share Wednesday before closing at $36.80, will we start to see more of its top executives unload ...

Campaign to Unload (@Campaign2Unload) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

All sizes - Day 066/365 - Unload Seniors Here - Flickr - Photo Sharing!
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

UK press unload on Rabbitohs code-hopper Sam Burgess
The finger-pointing is underway after Sam Burgess ended his ill-fated stint in rugby union and decided to return to the NRL.

Zuckerberg unloads Facebook shares (00:54)
In a bid to pay of his taxes, Facebook founder and CEO Mark Zuckerberg is selling 41.4 million shares worth $2.61 billion.

Origin Energy set to unload
Prospective bidders for Origin Energy’s stakes in the Cooper Basin and Western Australia’s Perth Basin will move into the data room next week. ...

Father unloads on police over drive-by shooting
An irate Canberra father says ACT Policing fell well short of the mark in its response to a drive-by shooting in Kambah.

Mitchell Starc returns as David Warner unloads in Indian Premier League
David Warner has continued his magnificent Indian Premier League form, blasting a superb 91 as his Sunrisers Hyderabad to a 16-run victory in ...

Waratahs captain Dave Dennis unloads on profligate side
The Waratahs are in danger of repeating the sins of last season if they do not sharpen up in attack quick smart.

Resources last updated: 3/10/2016 3:42:50 AM