0

我有一个按钮,它打开一个 diag Jquery 并显示一些 div。该对话框显示 2 个按钮(“确定”和“取消”)。

当我单击对话框“确定”时,我想执行函数背后的代码(C#.net)。

我怎样才能做到这一点?

$("#dialog").dialog({
    autoOpen: false,
    modal: true,
    title: "Image Full Size",
    draggable: true,
    resizable: false,
    show: 100,
    width: 900,
    height: 680,
    buttons:
        {
            "Ok": function () {
                $(this).dialog("close");
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });

例如:

在 C#.net 中调用 next 下面的函数

public void loadInfo()
{
    // Do something
}
4

2 回答 2

3

获得此功能的一种非常快速且简单的方法是使用带有事件 OnValueChange 的隐藏字段。

<asp:HiddenField ID="hf" clientidmode="static" runat="server" OnValueChanged="hf_ValueChanged" />

然后在你的脚本中:

"Ok": function () {
      $(this).dialog("close");
      $("#hf").value("1");
},
"Cancel": function () {
      $(this).dialog("close");
}
于 2013-09-02T12:44:45.440 回答
1
    one way that we needed to add our method as a webmethod, if we want to call   a method from code behind at client side   Write your loadInfo() Method server side    in   the  CS file and calling it from client side using JQuery. 

见下面的代码

  $("#dialog").dialog({
       autoOpen: false,
       modal: true,
       title: "Image Full Size",
       draggable: true,
       resizable: false,
       show: 100,
       width: 900,
       height: 680,
       buttons:
      {
           "Ok": function () {
             $.ajax({ type: "GET",
             contenttype: "application/json; charset=utf-8",
            data: "{null}",
           url: "WebService1.asmx/loadInfo",
           dataType:"json",
            success: function(res) {
           // Do something means binding data
     },
     error: function(err) {
     alert(err);
 }
   });   
         $(this).dialog("close");
        },
        "Cancel": function () {
            $(this).dialog("close");
        }
      }
 });
于 2013-09-02T13:02:29.657 回答