我必须通过我的一个方法运行下面的javascript。但它不能运行代码出了什么问题。
private void fillGrid1()
{
GridView1.DataSource = myDocCenter.GetDsWaitingForMe(Session["UserID"].ToString());
HiddenField1.Value = { myDocCenter.GetDsWaitingForMe(Session["UserID"].ToString()).Tables[0].Rows.Count).ToString();
GridView1.DataBind();
String csname1 = "PopupScript1";
String csname2 = "ButtonClickScript1";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
{
StringBuilder cstext2 = new StringBuilder();
cstext2.Append("<script type=\"text/javascript\"> ");
// You can add JavaScript by using "cstext2.Append()".
cstext2.Append("var count = document.getElementById('ctl00_ContentPlaceHolder1_HiddenField2');");
cstext2.Append("var count = '100';");
cstext2.Append("document.getElementById('sp2').innerHTML = count;");
cstext2.Append("script>");
cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
}
}发布于 2009-12-14 21:27:51
您的脚本标记未正确关闭。
变化
cstext2.Append("script>");至
cstext2.Append("</script>");发布于 2009-12-14 21:40:29
除了adamantium所说的,你的JS看起来有点奇怪。您似乎声明并设置了两次count变量--您是有意这样做的吗?
接下来,最好的做法是呈现页面,然后查看源代码。你的JS会被渲染到页面上吗?试着把警报放进去。它启动了吗?
发布于 2009-12-14 21:47:52
> cstext2.Append("var count =
> document.getElementById('ctl00_ContentPlaceHolder1_HiddenField2');");在这里,我将使用ClientID属性。HiddenField2.ClientID
https://stackoverflow.com/questions/1900911
复制相似问题