[英]Using javascript confirm dialog on a button within an UpdatePanel - posting back full page
我基本上想显示一个带有确认或取消选项的对话框。
确认应允许进行部分回发,而取消则不应。 我尝试使用触发器并按照此处的建议调用__doPostBack()
,但它会发回整个页面,而不仅仅是面板。
$('#buttonInUpdatePanel').live('click', function (event) {
event.preventDefault();
var item = this;
var title = 'Confirm';
var msg = 'Please confirm something';
var $dialog = $("<div id='myDialog'></div>")
.html(msg)
.dialog({
modal: true,
buttons: {
"Confirm": function () {
$(this).dialog("close");
__doPostBack('Button1', null); //tried this and .submit() on the button
//return true;
},
"Cancel": function () {
$(this).dialog("close");
//return false;
}
},
title: title
});
});
我的UpdatePanel:
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:TextBox runat="server" ID="TextBox1" />
<asp:Button
ID="Button1"
Text="Add"
OnClick="AddExtraVehicle_Click"
runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
更新:
我已经将doPostBack
更改为现在使用按钮ID,并注释掉了返回的真假行。
当我单击按钮时,它将调用确认对话框,但是当您单击确认时,它似乎无济于事。 我期待对方法AddExtraVehicle_Click
的调用,但断点没有触发。
更新:这个
__doPostBack('Button1', null)
不管用。 当ASP.NET呈现您的Button1时,该ID并不是真正的“ Button1”。 更改为包含其命名的ID。 你需要这样做
__doPostBack($('input[id$=Button1]').attr("id"), null); //You need to use the real ID of the button which this statement will do
您在正确的轨道上,但是稍微偏离了道路:)。 试试这个代码
var $dialog = $("<div id='myDialog'></div>")
.html(msg)
.dialog({
modal: true,
buttons: {
"Confirm": function () {
$(this).dialog("close");
__doPostBack($('input[id$=Button1']).attr("id"), null); //tried this and .submit() on the button
return true;
},
"Cancel": function () {
$(this).dialog("close");
return false;
}
},
title: title
});
});
基本上,您想使用已注册为更新面板的异步触发器的控件的ID调用__doPostBack。 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.