开发者

ASP.net Redirect to the calling page

开发者 https://www.devze.com 2023-03-16 03:59 出处:网络
I have a page that calls another page with some query string parameters. I want to return back to that page after clicking on a but开发者_JAVA百科ton.

I have a page that calls another page with some query string parameters. I want to return back to that page after clicking on a but开发者_JAVA百科ton.

I have to mention that I write that code in a user control and I don't know what page called that second page.

Is there something like Back button in browsers?


Simplest way use javascript on client side with

window.back();

For server side you need to save the url referer in page_load:

if(!Page.IsPostback)
{
  ViewState["GoBackTo"] = Request.UrlReferrer;
}

and on a button click using Response.Redirect:

Response.Redirect( ViewState["GoBackTo"].ToString() );

edit: please note ppumkin's comment below!


You could look at Cross Page Posting.

Alternatively, if you are generating the link programatically you could include the returnUrl in the url e.g. http://localhost/secondpage.aspx?returnurl=firstpage.aspx

You can then read this querystring parameter in the secondpage and perform as redirect back once your work is done.


You can use the Request.UrlReferrer, but it is not necessarily sent from the client all the time:

        Response.Redirect(Request.UrlReferrer.AbsoluteUri);


put this line of code on the page load event

 Btn_Back.Attributes.Add("onClick", "javascript:history.back(); return false;");
0

精彩评论

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

关注公众号