【发布时间】:2012-01-30 22:06:30
【问题描述】:
我试图在单击 asp:Button 控件后运行模式弹出窗口以显示确认消息。我以http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/ 的教程为基础。
目前,我的客户端操作正在运行,并且模式弹出窗口会显示我的消息和确认按钮。
我遇到的问题是为 yes 按钮设置 doPostBack:
__doPostBack([button I want to target], '');
我试过用:
<%=this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this.Button123))%>;
为doPostBack 命令查找按钮控件。这种方法的问题是,它在我可以选择加载模式之前触发回发。
使用从上述“GetPostBackEventReference”返回的硬编码 doPostBack
__doPostBack('ctl00$ContentPlaceHolderBody$Button123', '');
在模式中单击“是”后,我能够回发到正确的服务器 onClick 事件。
我想知道如何使用 ClientScript.GetPostBackEventReference 方法而不是在显示模式或替代方法之前回发。
任何帮助将不胜感激。
代码如下:
<asp:Button ID="Button123" runat="server" Text="Test" OnClick="Ctl_ButtonUpdateRecord_Click" />
$(document).ready(function () {
$("input[id$='Button123']").click(function () {
$.confirm({
'title': 'Delete Confirmation',
'message': 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?',
'buttons': {
'Yes': {
'class': 'blue',
'action': function () { <%=this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this.Button123))%>;
//__doPostBack('ctl00$ContentPlaceHolderBody$Button123', '');
}
},
'No': {
'class': 'gray'
}
}
});
return false;
});
});
(function ($) {
$.confirm = function (params) {
if ($('#confirmOverlay').length) {
// A confirm is already shown on the page:
return false;
}
var buttonHTML = '';
$.each(params.buttons, function (name, obj) {
// Generating the markup for the buttons:
buttonHTML += '<a href="#" class="button ' + obj['class'] + '">' + name + '<span></span></a>';
if (!obj.action) {
obj.action = function () { };
}
});
var markup = [
'<div id="confirmOverlay">',
'<div id="confirmBox">',
'<h1>', params.title, '</h1>',
'<p>', params.message, '</p>',
'<div id="confirmButtons">',
buttonHTML,
'</div></div></div>'
].join('');
$(markup).hide().appendTo('body').fadeIn();
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons, function (name, obj) {
buttons.eq(i++).click(function () {
// Calling the action attribute when a
// click occurs, and hiding the confirm.
obj.action();
$.confirm.hide();
return false;
});
});
}
$.confirm.hide = function () {
$('#confirmOverlay').fadeOut(function () {
$(this).remove();
});
}
})(jQuery);
【问题讨论】: