后台弹出消息框不会导致样式错乱的2种方法

第一种

Page.ClientScript.RegisterStartupScript和Page.ClientScript.RegisterClientScriptBlock

if (txtUsername.Text.Trim() == string.Empty)
{
  Page.ClientScript.RegisterStartupScript(
this.GetType(), "", "alert('收货人,不能为空!');",true);
  
return;
}

 

 

 第二种

Response.Write("<script>alert('收货人,不能为空!');history.go(-1);</script>");

如果缺少 history.go(-1); 样式会乱掉。

if (txtUsername.Text.Trim() == string.Empty)
{
  Response.Write(
"<script>alert('收货人,不能为空!');history.go(-1);</script>");
  
return;
}
posted @ 2010-05-05 15:32  一个IT愤青  阅读(408)  评论(0编辑  收藏  举报