I am calling this in my code behind:
(test.aspx)
Response.Redirect("~/Default.aspx");
I want to include a javascript alert after/before being redirected to Default.aspx, is it possible? I'm doing this because I'm passing a value to another page (test.aspx) and that page checks the db, if reader HasRow(), then redirect to Default.aspx.
这样做的方法是使用javascript显示警报,然后使用javascript进行重定向:
ScriptManager.RegisterStartupScript(this,this.GetType(),"Redit","alert('asdf'); window.location='" + Request.ApplicationPath + "Default.aspx';",true);
Lets take a look at what happens when you call response.redirect()
Now looking at this, we can deduce that it is impossible to tell the browser to do a alert() from the page that issues the redirect because its content (if any) is discarded.
It is possible to accomplish what you want from the page that you are redirecting to . To do this, just check Request.UrlReferrer to check if you were redirected from the correct page, then display the alert when appropriate.
example:
Another approach is do the alert first then do the redirect from javascript. window.location.href = newurl.
if you have display something message on Defaul.aspx page you must declare it. Because when you use redirect your page is rendering from top. You must set before redirect Sesion state on something flag and on Default.aspx page you must insert section who been added when this Sesion state been set.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.