This is a migrated thread and some comments may be shown as answers.

NumericTextBox SpinButtons firing the window.onbeforeunload event

1 Answer 37 Views
Input
This is a migrated thread and some comments may be shown as answers.
Mike Hale
Top achievements
Rank 1
Mike Hale asked on 01 Sep 2010, 04:14 PM
I have a NumericTextBox on a page that prompts the user when they try to navigate away from that page if they have unsaved changes.

My javascript:

 

window.onbeforeunload = function () {
  if (isDirty) {
    return 'You have unsaved changes. You will lose your changes if you leave the page.';
  }
};

 
The issue is that if I enable the spinbuttons on the numeric textbox this event fires whenever the user clicks the spin button, even though they don't navigate away. Is there a way to prevent this event from firing?

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 02 Sep 2010, 10:33 AM
Hello Mike,

The issue seems specific to IE. Here is how to avoid it.

We will modify the control's code, so that the workaround will not be needed in the next version of RadControls.


<%@ Page Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" ShowSpinButtons="true">
    <ClientEvents OnLoad="changeHrefs" />
</telerik:RadNumericTextBox>
 
<script type="text/javascript">
 
function changeHrefs(sender, args)
{
    if ($telerik.isIE)
    {
        $addHandler(sender.SpinUpButton, "click", returnFalse);
        $addHandler(sender.SpinDownButton, "click", returnFalse);
    }
}
 
window.onbeforeunload = function(event)
{
    alert("onbeforeunload");
}
 
function returnFalse(e)
{
    $telerik.cancelRawEvent(e);
    return false;
}
 
</script>
 
</form>
</body>
</html>


Regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Input
Asked by
Mike Hale
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or