当我点击对话框jquery的按钮时,执行代码隐藏功能



我有一个按钮,打开一个dilag Jquery并显示一些div。对话框显示两个按钮("ok"one_answers"Cancel")。

当我点击对话框"确定"时,我想执行一个代码隐藏函数(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 中的下一个函数

public void loadInfo()
{
    // Do something
}

获得此功能的一种非常快速而简单的方法是在事件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");
}
    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");
        }
      }
 });

最新更新