开发者

how do I return to the same exact page after posting a form?

开发者 https://www.devze.com 2022-12-23 16:23 出处:网络
I\'m posting data to a page called process.aspx that handles some business logic with the following code:

I'm posting data to a page called process.aspx that handles some business logic with the following code:

<%@ Page Language="C#" %>
<%
    MyData.process(Request);
    Response.Redirect("")
%>

this pa开发者_运维问答ge I will be calling from a variety of pages. Is there some way of knowing from which page my form was submitted? I was thinking something along the lines of writing:

 <form id="frmSystem" method="post" action="process.aspx?page=<%=  %>">

However I don't know what to write in between the <%= %> to get the current page name. Can anyone help please?


You can capture the calling page URL and hold it in Session or ViewState for later use.

For example, in Page_Load,

Session["PreviousPage"] = Request.Url.ToString();

And then in your final event (perhaps Savebutton_Click or CloseButton_Click), you can do a redirect in either of these ways:

Server.Transfer(Session["PreviousPage"].ToString(), false);

or

Response.Redirect(Session["PreviousPage"].ToString(), false);

You can also get the URL of the calling page this way:

Request.ServerVariables("HTTP_REFERER")


You could pass in it in via a property like the ReturnUrl similar how a sign in page works. This is kind of how you are doing it up there.

You could also try to use the HttpContext.Current.Request.UrlReferrer to see who referred you.


You can use Request.UrlReferrer.OriginalString to get the URI of the referring page.

0

精彩评论

暂无评论...
验证码 换一张
取 消