【问题标题】:Passing parameters from C# to Jquery function()将参数从 C# 传递到 Jquery function()
【发布时间】:2014-03-26 12:24:35
【问题描述】:

我在 asp.net 页面中有一个 gridview。每列都有一个按钮,单击该按钮我使用 jquery 打开一个弹出窗口。

 protected void gvExpiry_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((e.Row.RowType == DataControlRowType.DataRow))
            {
                Button tmp = new Button();
                tmp = ((Button)e.Row.FindControl("btnTest"));
                tmp.Attributes["onclick"] = "javascript:return MyFunc(" + gvExpiry.DataKeys[e.Row.RowIndex].Value.ToString() + "," + gvExpiry.DataKeys[e.Row.RowIndex].Value.ToString() + ")";

            }
        }



$("[id*=btnTest]").live("click", function () {           
             $("#modal_dialog").dialog({                 
                 close:function(event, ui){                       
                     $(this).dialog("close");
                 },
                 title: "Please enter tag",
                 buttons: {
                     Ok: function MyFunc(fileName, tag) {                        
                         //alert(fileName);
                         var etag = $("#<%= txttag.ClientID  %>").val(); 
                         alert(typeof fileName);
                         alert(typeof Etag)
                         //other functionality
 },
                 modal: true
             });
             return false;
         });

但是在我的 MyFunc(fileName, Etag) 中,我没有得到正确的参数值。我是 gettng 对象和未定义的值

我怎样才能得到我的参数的正确值

【问题讨论】:

  • 试试gvExpiry.DataKeys[e.Row.RowIndex]["your_datakeyname"].Value

标签: c# jquery asp.net .net


【解决方案1】:

尝试在函数调用中添加单引号,函数认为文本是变量,而不是字符串。

tmp.Attributes["onclick"] = "javascript:return MyFunc('" + gvExpiry.DataKeys[e.Row.RowIndex].Value.ToString() + "','" + gvExpiry.DataKeys[e.Row.RowIndex].Value.ToString() + "')";

【讨论】:

  • 你需要分析渲染的html,确保脚本没有错误。
猜你喜欢
  • 2011-10-17
  • 2013-01-28
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 2016-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多