ASP.NET Page Cycle Confusion

时光毁灭记忆、已成空白 提交于 2019-12-24 10:59:19

问题


If I have a button on my ASP.NET page which will take you to another page but that page will do something and then will send user back using

 Uri uu= Request.UrlReferrer;
        if (uu!= null)
            Response.Redirect(uu.ToString());

Now Which page event can I use so that when other pages displays I can display a message box.

In short I am running my custom code in a "aspx" page where user is directed on button click, and then after custom code I am sending user back to old page, but it happens so quickly that user doesn't realize that he went on another page, now I want to display a message box after redirect on same page user started from, what to do :S !

More Information

EDIT

Sorry guys but I can't make changes to ASP page where button is at all :(


回答1:


I'm a bit unsure about how the Request.UrlReferrer gets set. I think it's a browser implementation detail. So I wouldn't trust on that.

I would go for something like

A.aspx -> Redirects to -> B.aspx

B.aspx -> Redirects to -> B.aspx?message=1

And check if message=1 is set.

But if you want to use the Request.UrlReferrer it should be accessible on Page_Load




回答2:


If you use it this way, it'll never appear to the client. Maybe try redirecting back using javascript with a delay so user can be informed




回答3:


The best thing to do it's add a flag to the redirected page so you can show something special when the flag is turned on

Uri uu= Request.UrlReferrer;
if (uu!= null)
    Response.Redirect(uu.ToString() + "?Message=DataHasChanged");

and then in the ASP page

<% if (Request.QueryString["Message"] == "DataHasChanged") { %>
    <div class="alert">The data has changed. Please review it or whatever</div>
<% } %>


来源:https://stackoverflow.com/questions/13402297/asp-net-page-cycle-confusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!