msg 是存储过程的返回字符串,Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + msg + "')</script>");这么写程序没反映以前的程序这么写没问题的啊
现在response.Write("<script>alert('" + msg + "')</script>"); 可以弹出提示
我怀疑Page_load 加了cookie的原因 程序只改了这个 protected void Page_Load(object sender, EventArgs e)
{ if (Request.Cookies["userid"] != null)
{
//Response.Write(Request.Cookies["userid"].Value);
c = Request.Cookies["userid"].Value;
if (c == "" || (c.Substring(0,2)!="kf" && c.Substring(0,3)!="adm"))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>document.getElementById('gettaodata').style.display='none'</script>");
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>document.getElementById('gettaodata').style.display='none'</script>");
}
}不知道哪错了
现在response.Write("<script>alert('" + msg + "')</script>"); 可以弹出提示
我怀疑Page_load 加了cookie的原因 程序只改了这个 protected void Page_Load(object sender, EventArgs e)
{ if (Request.Cookies["userid"] != null)
{
//Response.Write(Request.Cookies["userid"].Value);
c = Request.Cookies["userid"].Value;
if (c == "" || (c.Substring(0,2)!="kf" && c.Substring(0,3)!="adm"))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>document.getElementById('gettaodata').style.display='none'</script>");
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>document.getElementById('gettaodata').style.display='none'</script>");
}
}不知道哪错了
如若你什么报错都没有的话,绝对是你的js有问题的
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + msg + "')</script>");
msg 里面的内容不能有换行,单引号等特殊字符才可以,正确的写法是
msg = msg.Replace("\r\n","\\r\\n").Replace("'","\\'");
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + msg + "')",true);
{
String msg = "ok";
msg = msg.Replace("\r\n","\\r\\n").Replace("'","\\'");
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + msg + "')",true);
}这样不行?
你也可以查看浏览器源代码,看看源代码里面是否生成了
alert("")
这行代码
response.write() 源文件 上面的是 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + msg + "')</script>",true); 源文件
在页头的response.write()出来的内容会破坏页面的css的。Page.ClientScript.RegisterStartupScript生成的代码是在</form>这个结束标记的前面的
if(!Ispostback)
{ }Page.ClientScript.RegisterStartupScript 起作用