我试图在点击一个asp:按钮控件后运行确认消息的模式弹出窗口。我使用http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/的教程作为基础。jQuery模式弹出确认 - 处理服务器端回发
目前我有客户端操作工作和模式弹出与我的消息和确认按钮。
我遇到的问题是与设置doPostBack为Yes按钮:
__doPostBack([button I want to target], '');
我试着使用:
<%=this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this.Button123))%>;
为doPostBack命令查找按钮控制。这个方法的问题是,在我有一个加载模式的选项之前,它会触发回发。
使用从上面的“GetPostBackEventReference”
__doPostBack('ctl00$ContentPlaceHolderBody$Button123', '');
我能够点击的模式是经过回发到正确的服务器onClick事件返回的硬编码doPostBack。
我想知道如何使用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);
我在外部文件上使用这些脚本时遇到问题。我能够直接在页面上运行服务器端脚本,但无法在外部.js文件中运行它。 – 2012-01-31 14:22:51
您将无法在外部JavaScript文件中正确执行“Page.ClientScript.GetPostBackEventReference”指令,因为它不会像'asp.net'页面那样被“处理”。您可以做的唯一事情就是将这部分直接包含在您的页面上。 – MonkeyCoder 2012-01-31 16:19:03