this.Page.RegisterStartupScript("shownote", "<script>tt(\"" + name + "\");</script>");
后台的引号不要与前台脚本里的引号混淆

解决方案 »

  1.   

    在js里有个函数function tt(a)  {    alert(a);    }
    在后台调用问什么
     protected void Button3_Click(object sender, EventArgs e)
        {
            string name = "1111";
            this.Page.RegisterStartupScript("shownote", "<script>tt(" + name + ");</script>");
        }
    可以,而
    protected void Button4_Click(object sender, EventArgs e)
        {
            string gg = "gfds";
            this.Page.RegisterStartupScript("shownote", "<script>tt(" + gg + ");</script>");
        }
    就报gfds未定义啊??应该如何改啊??
      

  2.   

    因为变量类型问题~!上面代码生成为<script>tt(1111);</script>和<script>tt(gfds);</script>,而在JS里gfds是一个变量,所以出错。应该为"<script>tt('" + gg + "');</script>")