ASP .NET调用javascript中Response.Write和ClientScript.RegisterStartupScript的区别
最近在用ASP .NET的code behind 调用javascript中发现Response.Write不能拿到form的值,而ClientScript.RegisterStartupScript可以。例如下面的代码
可以明显的看到,Response.Write得到的是0,ClientScript.RegisterStartupScript得到的是1。
1 StringBuilder sb = new StringBuilder();
2 sb.Append("<script language=javascript>");
3 sb.Append("alert(document.forms.length);");
4 sb.Append("</script>");
5
6 Response.Write(sb.ToString());
7 ClientScript.RegisterStartupScript(this.GetType(), "test", sb.ToString());