使用ClientScriptManager将JavaScript添加到页面 - c#

我正在尝试使用ClientScriptManager将JavaScript添加到页面,但是脚本没有被添加到页面。 'trendsTable'包含一个asp:Gridview并且其显示设置为none,但是在单击'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());

        }
    }

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

参考方案

您正在定义一个函数,但未调用它。更改:

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

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

javascript popupwindow之后的行如何工作? - javascript

好的,我有一个来自后面代码的方法,可以创建一个popupwindow。然后有一行代码要在那之后执行,我想知道那行代码何时执行,是在使用popupwindow之后执行还是在创建popupwindow之后执行?例如:void exPopupWindowMethod() { string scr = "window.open('exampleP…

ddl在服务器中未更新-asp.net - javascript

我在ASP.NET c#上工作。我有一个DropDownList。 (runat =“ server”)在$ {document).ready上,我更新了它的值:$(document).ready(function () { document.getElementById("ddl").value = "abc"; ……

.NET C#Webbrowser填充输入,不带ID或类名 - javascript

我需要在网络浏览器中填写一个输入,但这不起作用。我认为必须使用name属性来完成,但是怎么做呢?foreach (HtmlElement login in webBrowser1.Document.GetElementsByTagName("input")) { if (login.GetAttribute("name"…

从控制器以视图(javascript)访问会话 - javascript

这是我的控制器代码。我想获取视图中存储在会话中的值(JavaScript代码) decimal.TryParse(permotion.PROMOTION_AMOUNT.ToString(), out promotionAmount); int.TryParse(permotion.PROMOTION_TYPE_ID.ToString(CultureInfo.…

获取JavaScript值到C#字符串 - javascript

                        是否可以在C#中执行类似的操作?该值为“ 10/05/2014”string jsValue = javascript("$('#EstimatedStartDate').val()"); 参考方案 您能否更详细地阐明您要做什么。看来您正在尝试从javascript(客户…