Webform unload event - Easy question for somebody!

Posted on 2006-05-23
Last Modified: 2008-02-01
I create my event from the event section of the property window...

            private void wfTimesheet_Unload(object sender, System.EventArgs e)
                  Response.Write("test test test tset");

I put a breakpoint on the Response.Write....  It never gets there..

What am I doing wrong?!


Question by:djdidge
    LVL 2

    Author Comment

    all I want to do is run a stored procedure on window close....
    LVL 5

    Accepted Solution


    1. Hope u can use the onbeforeunload() event of the body tag..
    2. Place an iframe in u r form.
    3. Add a webform to u r project.. (eg.. downloadController.aspx)  in the server side page load event just call u r code to execute the stored procedure..
    3. in the onbeforeunload event of the form assign the iframe to the downloadController.aspx page
        ( myIFrame.location.href = "downloadController.aspx"; )

    Source page:-

    <body onbeforeunload="beforeClose();"  MS_POSITIONING="GridLayout">
                <form id="Form1" method="post" runat="server">
                      <iframe name="myIFrame" id="myIFrame" runat="server" src="" style="DISPLAY: none"></iframe>

    In the beforeClose() function in client side..

    function closeDocument()
                myIFrame.location.href = "downloadController.aspx";  

    LVL 2

    Author Comment

    thanks, ill give it a go....

    Seems odd that the unload event doesnt allow this though..
    LVL 2

    Author Comment

    I'm getting there I think. I understand the concept. But there are a few niggles.
    In its preset state the web form wfClearBlankRows.aspx is never touched. (breakpoint tested).
    (note that im new to Javascript!)

    also.....  myIFrame.location is not exposed by the intellisense.

    Here is the cropped code so far....................

                <title>Time Keeping</title>
                <base target="_self">
                <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
                <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
                <meta content="JavaScript" name="vs_defaultClientScript">
                <meta content="" name="vs_targetSchema">
                <!-- <LINK href="styles/evolve.css" type="text/css" rel="stylesheet"> -->
                function beforeClose()
                          myIFrame.location.href = "wfClearBlankRows.aspx";  
          <body onbeforeunload="beforeClose();" MS_POSITIONING="GridLayout">
                <form id="Form1" method="post" runat="server">
                      <iframe id="myIFrame" style="DISPLAY: none" name="myIFrame" src="" runat="server"></iframe>

    LVL 2

    Author Comment

    I couldnt quite get it to work... but the logic is there.

    Closed the queston to be tidy....

    Thanks - didge

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now