Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Use JavaScript onbeforeunload to call routine

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2005-08-22 : 15:40:52
I have a datagrid hyperlink, and I want to call the routine, WPSaveInfo(), before the user goes to the next page via the hyperlink. WPSaveInfo() saves the data the user entered on the page, just in case they didn't click the SAVE button.

I know the script is something like the following, but I don't have it correct:

Dim strScript As String
strScript =
"<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
Call WPSaveInfo()
}
<" & Chr(47) & "script> "


Where do I put this javascript? In Page_Unload?
How do I call this WPSaveInfo() routine? I know it's not Javascript.

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-08-22 : 18:05:50
So, WPSaveInfo is a server-side routine, not client-side JavaScript? Is there just one Hyperlink you are worried about them using? You could make that Hyperlink do a postback like a form submittal, and then on the server side do a redirect after the WPSaveInfo routine has run.

---------------------------
EmeraldCityDomains.com
Go to Top of Page

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2005-08-22 : 18:52:35
AjarnMark,

Thanks for the reply.

The control was an <asp:hyperlink>.
I fixed the issue by:
1. Changing it to a linkbutton
2. Ran the datagrid's itemcommand looking for the linkbutton's commandname
3. Called WPSaveInfo() from this itemcommand handler

Thanks!
Go to Top of Page
   

- Advertisement -