Reputation: 1133
I have a user control including a list view that includes a hyperlink (LnkDelete) to popup a jQuery dialog.
This is the javascript code that does the work
$('#LnkDelete').live('click', function (e) {
var page = $(this).attr("href");
var $dialog = $('<div></div>')
.html('<iframe style="border: 0px;" src="' + page + '" width="100%" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
height: 200,
width: 600,
title: "Are you sure you want to delete ...?"
});
$dialog.dialog('open');
e.preventDefault();
});
This is the hyper link that opens the "DeleteBranch" web form as a dialog:
<asp:HyperLink ID="LnkDelete" runat="server" NavigateUrl='<%# Eval("ID", "~/Personnel/DeleteBranch?Id={0}") %>' ClientIDMode="Static" CssClass="button-delete" />
The "DeleteBranch" web form includes a user control with "Ok" and "Cancel" ASP buttons. The "Ok" button simply performs the delete operation of the related row in the original listview.
The question is: How to make the "Cancel" button closes the popup?
Upvotes: 0
Views: 394
Reputation: 6860
$('#LnkDelete').live('click', function (e) {
var page = $(this).attr("href");
var $dialog = $('<div></div>')
.html('<iframe style="border: 0px;" src="' + page + '" width="100%" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
height: 200,
width: 600,
title: "Are you sure you want to delete ...?",
buttons: [
{
text: 'OK',
click: function() { /*Your delete operation*/ }
},
{
text: "Cancel",
click: function() { $dialog.dialog('destroy'); }
}
]
});
$dialog.dialog('open');
e.preventDefault();
});
As you said, in case of your ASP buttons, give that button a ID
like btn_cancel
and add the following script:
<script lang='javascript'>
$(document).ready(function(){
$('#btn_cancel').click(function(){
$dialog.dialog('destroy');
});
});
</script>
Upvotes: 2