admin管理员组文章数量:1287638
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.
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.
Share Improve this question asked May 19, 2011 at 5:40 Pod MaysPod Mays 2,5937 gold badges31 silver badges45 bronze badges3 Answers
Reset to default 5The way to do that is display the alert with javascript and then do the redirect with javascript as well:
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()
- Servers sends HTTP response 302 to browser including the url to navigate to
- browser doesn't display content of response and instead gets the content from the url specified
- if the request to the new url succeeds, then it is displayed.
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 acplish 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:
- Page1 redirects to page2
- Page2 check if Request.UrlReferrer is equal to page1
- If equal, display alert
- If not, do nothing special
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.
本文标签: cJavascript alert() after ResponseRedirectStack Overflow
版权声明:本文标题:c# - Javascript alert() after Response.Redirect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741237660a2363338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论