ASP.NET使用jQuery弹出对话框:如何发布回到对话闭幕 [英] ASP.NET with jQuery popup dialog: how to post back on dialog closing

查看:185
本文介绍了ASP.NET使用jQuery弹出对话框:如何发布回到对话闭幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

我工作的一个相当复杂的网站。我们有一个包含一些控件的更新面板。当单击控件之一,将打开一个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 the UpdatePanel or outside and set it as an AsyncPostBackTrigger.
  • Call the js function from ItemDataBound if needed, passing in the ClientID of the hidden asp: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 the UpdatePanel or call Update within the butHidden_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆