jQuery newbie here. I've looked at dozens of similar questions on this site, as well as the answers provided so far here, all having pretty much the same response, and I've tried all of them, but nothing is working for me.
For the Javascript code in my .aspx, I currently have:
<script type="text/javascript" src="/resources/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/resources/jquery-ui-1.8.20.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="/resources/ui-lightness/jquery-ui-1.8.20.custom.css" />
<script language="javascript" type="text/javascript">
$(function() {
var $myDialog = $("#cancelDialog").dialog({
autoOpen: false,
modal: true,
buttons: {
'Yes, cancel': function() {
$(this).dialog('close');
return true;
},
'No, resume editing': function() {
$(this).dialog('close');
return false;
}
}
});
$("[id$=btnCancel]").click(function(e) {
//e.preventDefault();
alert('boo');
//$myDialog.dialog('open');
});
});
</script>
The markup for "btnCancel" looks like this - notice that I don't have an "onClientClick" attribute because jQuery is supposed to do this for me, right?
<asp:Button ID="btnCancel" CssClass="btnCancel" runat="server" Text="Cancel"
CausesValidation="false" UseSubmitBehavior="false" />
And here's the markup I have for the cancellation dialog:
<div id="cancelDialog" style="display: none;" title="Please confirm cancellation">
<p>Are you sure you wish to cancel and abandon your changes?</p>
</div>
According to all the examples I've seen (and the answers provided here), this should give me a jQuery UI popup with my two buttons that just works. The page is no longer posting back when I hit the cancel button (due to the changes I made at Patrick Scott's suggestion). I could just use a standard Javascript confirm() dialog for this, but I want to be able to customize the prompts/styling.
The only other information I can think of to throw in is that this code is on an ASP.NET Wizard control (the cancel button is in the StepNavigationTemplate), but that shouldn't matter, should it?
Any hints as to what I need to change to get this working are greatly appreciated!
(question & code updated to reflect recent changes I've made)