【问题标题】:Adding JavaScript to page using ClientScriptManager使用 ClientScriptManager 将 JavaScript 添加到页面
【发布时间】:2014-05-08 22:29:47
【问题描述】:

我正在尝试使用 ClientScriptManager 将 JavaScript 添加到页面,但脚本没有添加到页面中。 'trendsTable' 包含一个 asp:Gridview 并且它的显示设置为无,但是在单击“RequestReport”时,我希望将数据绑定到 gridview,dataTabletester 执行此操作,然后将“trendsTable”的显示设置为表格。

protected void RequestReport_Click(object sender, EventArgs e)
    {
        //method to bind data to table
        dataTabletester();

        //insert script to make table visible
        String csname1 = "PopupScript";
        Type cstype = this.GetType();

        //Get a Client ScriptManager reference from Page Class

        ClientScriptManager cs = Page.ClientScript;

        if (!cs.IsStartupScriptRegistered(cstype, csname1))
        {
            string script = "function() {document.getElementById('trendsTable').style.display = \"table\";}";


            StringBuilder cstext1 = new StringBuilder();
            cstext1.Append("<script type=text/javascript>");
            cstext1.Append(script);
            cstext1.Append("</script>");

            cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());

        }
    }

感谢任何可以提供任何帮助的人。

【问题讨论】:

    标签: c# javascript asp.net clientscriptmanager


    【解决方案1】:

    您正在定义一个函数,但没有调用它。变化:

    string script = "function() {document.getElementById('trendsTable').style.display = \"table\";}";
    

    string script = "document.getElementById('trendsTable').style.display = \"table\";";
    

    【讨论】:

      猜你喜欢
      • 2012-02-27
      • 2019-01-07
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多