Reputation: 27
I'm trying to set window.onbeforeunload to null for every asp Button as they are prompting my "Are you sure you want to close browser" message even they the button is just redirecting them.
$('#asp:button').click(function () {
alert("asp test working");
window.onbeforeunload = null;
});
So this is the above code i'm trying to access all asp:button to set window.onbeforeunload to null.
function confirmExit() {
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?"; }
And this is my prompt code.
For some reason, I can't get the first section code to work, the alert dont even appear!
Any pointers?
Upvotes: 1
Views: 668
Reputation: 19465
Basically #asp:button
isn't the ID of your submit buttons. Asp.net gives them a unique ID which can be accessed in your aspx views like this <%=myBtn.ClientID%>
In your view (.aspx page) you could loop through all your asp.net buttons and access them with <%=myBtn.ClientID%>
OR you could just set the selector to all inputs, like @ShadowWizard mentions:
$("input[type=submit]")
OR, you could set a the CssClass
property (See here) for all your target buttons on page load or something and then target them in jquery from that class.
Lets say you do set all buttons.CssClass = "mybuttons";
Then you JS would be:
$('.mybuttons').click(function () {
Upvotes: 2
Reputation: 66397
Since <asp:Button>
is translated to ordinary submit button, you need such selector:
$("input[type=submit]").click(function () {
//...
});
Upvotes: 1