gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 12:40:21 24 4
gpt4 key购买 nike

我尝试使用 ClientScriptManager 将 JavaScript 添加到页面,但脚本未添加到页面。 “trendsTable”包含一个 asp:Gridview ,其显示设置为无,但单击“RequestReport”时,我希望将数据绑定(bind)到 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\";";

关于c# - 使用 ClientScriptManager 将 JavaScript 添加到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23553686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com