[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Webform unload event - Easy question for somebody!

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?!


  • 4
1 Solution
djdidgeAuthor Commented:
all I want to do is run a stored procedure on window close....

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";  

djdidgeAuthor Commented:
thanks, ill give it a go....

Seems odd that the unload event doesnt allow this though..
djdidgeAuthor Commented:
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="http://schemas.microsoft.com/intellisense/ie5" 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>

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

Closed the queston to be tidy....

Thanks - didge

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now