How to redirect to previous page, from where the redirect to current page? using C# Asp.net 4.0

Posted by Mahe under C# on 8/14/2012 | Points: 10 | Views : 15041 | Status : [Member] | Replies : 2
Hi All,

How to redirect to previous page, from where the redirect to current page? using C# Asp.net 4.0

Regards,
Mahe




Responses

Posted by: Ranjeet_8 on: 8/14/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,
it will redirect u to previous page.

<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="javascript:history.go(-1)">
Go To Previous Page </asp:LinkButton>
OR,
<a href="javascript:history.go(-1);">Go To Previous Page</a>


Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajkatie on: 8/14/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
In current Page
protected void Page_Load(object sender, EventArgs e)
{

if (Page.IsPostBack == false)
{
ViewState["prevPageURL"] = Request.UrlReferrer.ToString();
}
}

protected void BackButton_Click(object sender, EventArgs e)
{
object pageURL = ViewState["prevPageURL"];

if (ViewState["prevPageURL"] != null)
{
Response.Redirect(pageURL.ToString());
}
}

Rajesh Patel
.Net Trainer(M.C.S.A | MCT)
Brainbench (Asp.Net 4.5 and C# 5.0)

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response