如何显示在asp.net消息框 [英] how to show message box in asp.net
本文介绍了如何显示在asp.net消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用C#创建一个网站,我想显示一个消息框。我试图使用JavaScript这种情况下,它运行,如果我做到以下几点:
I'm using C# to create a website and I'm trying to show a message box. I'm trying to use JavaScript for this situation and it runs if I do the following:
Response.Write("<script LANGUAGE='JavaScript' >alert('Login Successful')</script>");
但是,如果不是我这样做:
However if instead I do this:
Response.Write("<script LANGUAGE='JavaScript' >alert('Login Successful')</script>");
Response.Redirect("~/admin.aspx");
该消息框不会被显示。
The message box doesn't get shown.
这是为什么,我该如何解决这个问题?
Why is this and how can I fix it?
推荐答案
做一个Response.Redirect的你实际上是在发送后立即302重定向到客户端,因此警报从未真正被用户的浏览器呈现。相反,尝试这样的事情
By doing a Response.Redirect right after you're actually sending a 302 redirect to the client, so the alert is never actually being rendered in the user's browser. Instead, try something like this
Response.Write("<script LANGUAGE='JavaScript' >alert('Login Successful');document.location='" + ResolveClientUrl("~/admin.aspx") +"';</script>");
这篇关于如何显示在asp.net消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文