Response.write后马上运行Response.redirect,Response.write没反应

我们时常想达到这样的效果:

Response.Write("<script>alert("您离线时间过长,请重新登陆!");</script>");

Response.Redirect("Login.aspx");

我们希望先提示信息,然后再跳转页面。但这样做的结果是:直接跳转,没有提示信息。

这是为什么呢?

<wbr></wbr>

<wbr></wbr>

Response.Redirect方法之后,这个页面的内容根本就不会被发送到客户端,而是直接在服务器端跳转了,所以不管页面有什么内容,客户端都无法看到自然也无法运行。

<wbr></wbr>

怎么修改呢?

<wbr></wbr>

方法一:

public class BasePage:System.Web.UI.Page
<wbr><wbr><wbr> {<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> public BasePage()<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> {<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> this.Load += new EventHandler(BasePage_Load);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> }</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><wbr><wbr> void BasePage_Load(object sender, EventArgs e)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> {<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> if (Session["usernum"]==null)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> {<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><strong><span style="color:#ff0000">Response.Write("&lt;script languge='javascript'&gt;alert('离线时间过长');</span></strong></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> window.location.href='Login.aspx'&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Response.End();<br></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> }</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><wbr><wbr> }<br><wbr><wbr><wbr> }</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr></wbr>

<wbr></wbr>

方法二(带有参数):

Response.Write("<script<wbr>languge='javascript'&gt;alert('成功修改');<wbr>window.location.href='index.aspx?par =" + param +<wbr>"'&lt;/script&gt;);</wbr></wbr></wbr>

Response.End();

<wbr></wbr>

<wbr></wbr>

为什么说Response。End()不可少呢?请看我的另一篇博客。《利用Page事件进行统一身份验证》。

<wbr><a href="http://blog.sina.com.cn/s/blog_67aaf4440100ms1c.html">http://blog.sina.com.cn/s/blog_67aaf4440100ms1c.</a><a href="http://blog.sina.com.cn/s/blog_67aaf4440100ms1c.html">html</a></wbr>

阅读更多
换一批

没有更多推荐了,返回首页