0

我正在尝试使用 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());

        }
    }

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

4

1 回答 1

1

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

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

string script = "document.getElementById('trendsTable').style.display = \"table\";";
于 2014-05-08T22:38:49.843 回答