【asp:LinkButton】LinkButton搭配JQuery UI Dialog确认窗口

【问题描述】

  在使用asp:LinkButton做删除时,需要做客户端确认,常规方法诸如confirm('***'),等等,很难满足现在WEB开发中的需要,在考虑使用jQuery UI的Dialog时,常常出现Dialog刚刚弹出,LinkButton的事件就迫不及待地触发掉。

【解决方案】

  1.在Dialog中添加如下代码:

eval($(this).dialog('option', 'onOk'));  

  2.绑定客户端单击事件时加上下面一行代码:

.dialog('option', 'onOk', $(this).attr('href'))
3.完整示例代码如下(引用):

确认删除
$(document).ready(function () {
$(
'#dialog-confirm-cancel').dialog({
autoOpen:
false,
modal:
true,
buttons: {
"Delete all items": function () {
// invoke the href (postback) of the linkbutton,
// that triggered the confirm-dialog
eval($(this).dialog('option', 'onOk'));
$(
this).dialog("close");
},
Cancel:
function () { $(this).dialog("close"); }
}
});

$(
'.btnDelete').click(function () {
$(
'#dialog-confirm-delete')
// pass the value of the LinkButton's href to the dialog
.dialog('option', 'onOk', $(this).attr('href'))
.dialog(
'open');
// prevent the default action, e.g., following a link
return false;
});
});

【参考文章】

  http://stackoverflow.com/questions/4133994/using-jquery-ui-dialog-as-a-confirm-dialog-how-to-invoke-the-default-action

posted @ 2011-01-20 09:54  玄黄道长  阅读(1609)  评论(0编辑  收藏  举报