ASP.NET使用jQuery弹出对话框:如何发布回到对话闭幕 [英] ASP.NET with jQuery popup dialog: how to post back on dialog closing
问题描述
伙计们,
我工作的一个相当复杂的网站。我们有一个包含一些控件的更新面板。当单击控件之一,将打开一个jQuery的对话框。
I'm working on a rather complicated site. We have an update panel that contains some controls. When one of the controls is clicked, a jQuery dialog box opens.
在该对话框关闭,我想信号更新面板以改变其显示。要做到这一点,我需要发送回更新面板。
When the dialog box closes, I want to signal the update panel to change its display. To do that I need to post back to the update panel.
我知道该对话框,您可以连接到一个方便的回调事件。但这里的东西。该操纵对话框中的JavaScript是所有在一个单独的.js文件。我要继续保持它分开。因此,code,做回发了既可以在.js文件,或注射作为参数传入的.js文件中的一些方法。
I know the dialog box has a handy callback event that you can hook up to. But here's the thing. The javascript that manipulates the dialog is all in a separate .js file. I want to continue keeping it separate. So the code that does the postback has either be in that .js file, or injected as a parameter into some method in the .js file.
我怎样才能做到这一点?而我会传递给js文件的方法呢?
How can I do that? And what would I pass to the .js file methods?
非常感谢。
推荐答案
刚把最近解决这个问题。我有一个通用的功能,以帮助这个问题。
Just had to solve this recently. I have a generic function to help with the issue.
- 把隐藏的
ASP:按钮
在的UpdatePanel
或境外,并将其设置为AsyncPostBackTrigger
。 - 通话从
的ItemDataBound
如果需要的js函数,传递客户端ID
隐藏ASP:按钮
。 - JS的函数将调用传递在曾经的OK或者你设置的
buttonTxt
来,按钮被点击的按钮的Click事件。 - 您就可以办理
UpdatePanel.Update
如果自动按钮是的UpdatePanel
或致电<$ C内$ C>更新的butHidden_Click
。
- Put a hidden
asp:button
within theUpdatePanel
or outside and set it as anAsyncPostBackTrigger
. - Call the js function from
ItemDataBound
if needed, passing in theClientID
of the hiddenasp:button
. - The js function will call the click event on the button passed in once the "OK" or whatever you set
buttonTxt
to, button is clicked. - You can then handle the
UpdatePanel.Update
automatically if the button is inside theUpdatePanel
or callUpdate
within thebutHidden_Click
.
标记:
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:button id="btnHidden" style="display:none" runat="server" onclick="btnHidden_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
脚本:
function showjQueryUIDialogOkBtnCallback(buttonToClick, dialogSelector, buttonTxt, isModal, width, height)
{
var buttonOpts = {};
buttonOpts[buttonTxt] = function () {
$("#" + buttonToClick).trigger('click');
};
buttonOpts['Cancel'] = function () {
$(this).dialog("close");
$(this).dialog('destroy');
}
$(dialogSelector).dialog({
resizable: false,
height: height,
width: width,
modal: isModal,
open: function (type, data) {
$(this).parent().appendTo("form"); //won't postback unless within the form tag
},
buttons: buttonOpts
});
$(dialogSelector).dialog('open');
}
这篇关于ASP.NET使用jQuery弹出对话框:如何发布回到对话闭幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!