Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 297 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hyperlink to go back to previous page in asp .net

#1
I have a page in asp .net `(

[To see links please register here]

).`

There is a link in page, on clicking on which has to go back to previous page from where I came from.

<a href="#">Go Back to Previous Page.</a>

How can I go back to previous page by taking from history
Reply

#2
you can use this:

<a href='javascript:history.go(-1)'>Go Back to Previous Page</a>
Reply

#3
use this code


<html>
<head>
<script>
function goBack()
{
window.history.back()
}
</script>
</head>
<body>

<a href="#" onclick="goBack()">Back</a>

</body>
</html>
Reply

#4
You should add an attribute which is about onclick like below:

protected void Page_Load(object sender, EventArgs e)
{
yourButton.Attributes.Add("onClick", "javascript:history.back(); return false;");
}

protected void yourButtonClick(object sender, EventArgs e)
{
Response.Write("Stackoverflow <br/>");
}


This is about using a button to go previous page, you can modify it according to your changes.
Reply

#5
For Going to previous page

**First Method**

<a href="javascript: history.go(-1)">Go Back</a>

**Second Method**

<a href="##" onClick="history.go(-1); return false;">Go back</a>

if we want to more than one step back then increase

For going 2 steps back history.go(-2)
For going 3 steps back history.go(-3)
For going 4 steps back history.go(-4)
and so on........
Reply

#6
I found this example

<input type="button" value=" <-- BACK " onclick="history.go(-1);return false;">

Just put this your page, it is working.
Reply

#7
I've been looking at this all weekend and haven't found the answer I was looking for. The problem is, after a postback history.go(-1); will not go back to where you want to go - that is, the page that got you there (with any changes made).

Using Request.UrlReferrer.ToString(); will reload the page you are going back to and you may be like me and not want to lose any changes that were made to the page. Above Rizwan Gill in 2013 hit on the answer that you want to go back 2, 3 or 4 pages but he didn't give a good way to do it.

The best way to do this is actually to use a pop-up modal for your page when it is called if your are writing the calling page but if you want to do it this way and have a back button you'll have to remember each postback and count them.

So, start with your hidden field (in your .aspx file) :

<asp:hiddenfield id="fldPostbackCount"
value="0"
runat="server"/>

Then increment the value with each postback (in your .aspx.vb file):


Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
fldPostbackCount.Value = 1
Else
fldPostbackCount.Value = Int32.Parse(fldPostbackCount.Value) + 1
End If

End Sub ' Page_Load()

(I'm sure the .cs people can handle the to C conversion on this)



Now back to your .aspx file you have to have a history button:

<a href="javascript:history.go(-<%: fldPostbackCount.Value %>)" title="Back to Previous Page">Back to Previous Page</a>




Reply

#8
If you are using asp.net then remember that

javascript:history.go(-1)
and

window.history.back()

Both will take you to back page. <br/>
But the previous page will not be exactly previous page.<br/>
For example
---
Suppose you are on page `Default.aspx` and there is a `asp:button`<br/>
Now when you click on the button and you are back on `Default.aspx`<br/>
**in this situation your previous page is still you Default.aspx**

**Take another exapmle<br/>**
You have two pages `Default1.aspx` and `Default2.aspx`
<br/>
**Condition 1**:- button clicked on `Default1.aspx` which redirect you to `Default2.aspx`<br/>
ok your previous page is `Default1.aspx`
<br/>
**Condition 2**:- button clicked on `Default1.aspx` and post back on the same `Default1.aspx` page
<br/> Now your previous page is still `Default1.aspx`

-------
**Edit**


protected void Page_Load(object sender, EventArgs e)
{
if( !IsPostBack )
{
ViewState["RefUrl"] = Request.UrlReferrer.ToString();
}
}
and use this in back button as follows

protected void Button3_Click(object sender, EventArgs e)
{
object refUrl = ViewState["RefUrl"];
if (refUrl != null)
Response.Redirect((string)refUrl);
}
Reply

#9
Following the example of शेखर

I would suggest to do the following and avoid any cycle on the url while posting back.

string from = Request.UrlReferrer.ToString();
string here = Request.Url.AbsoluteUri.ToString();

if(from != here)
Session["page"] = Request.UrlReferrer.ToString();

On your button click

object refUrl = Session["page"];
if (refUrl != null)
Response.Redirect((string)refUrl);

This will save always the PAGE you are coming from.

Hope it helps.
Reply

#10
In your C# code just write this:

Response.Write("<script>history.go(-1);</script>");
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through