Nikhil Bichewar

Nikhil Bichewar

  • NA
  • 250
  • 26.1k

jquery onbeforeload event prevent

May 20 2017 5:11 PM
I want to show message before leave the same page but prevent it on button clcik and drop down selected index changed below is coe.
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
};
$(function () {
$("#<%= ddlbranch.ClientID %>").change(); (function () {
window.onbeforeunload = null;
});
$("#<%= Button1.ClientID %>").click(); (function () {
window.onbeforeunload = null;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="SAVE" OnClick="Button1_Click" />
<asp:DropDownList ID="ddlbranch" runat="server" OnSelectedIndexChanged="ddlbranch_SelectedIndexChanged" AutoPostBack="true" />
</div>
</form>
</body>
</html>
 

Answers (1)