我試圖在點擊一個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