• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Browser Back via codebehind

Is there a way to redirect to the last page (just like clikc back on the browser) via c# codebehind?

Response.Redirect() is NOT what i am looking for. Say for example i scroll half way down a page and click a link... it posts me to another page. I then clikc back on my browser and will endup on the previous page, half way down, exactly where i left it... I need to do this via C#

Also using javascript (history.back()) produces the results i want BUT i want to do it from the codebehind.

Nugs
0
Nugs
Asked:
Nugs
  • 2
1 Solution
 
REA_ANDREWCommented:
I believe you would have to use javascript to store the scroll top position into a hidden field on each page.  Everytime you postback you get this value using

Request.Form["YourHiddenFieldName"] as javascript will have populated this field, without using ajax this is the only way to retrieve this value.  Once you have obtained this value, store it into a session as previous scroll position or something along with the url maybe.  When you load and page and is not postback check the URL is what you are on and if it has a value, Register a start up script to makee the page scroll to that position using javascript;

using ajax you can store this value to the session directly.

Andrew
0
 
NugsAuthor Commented:
So what you trying to tell me that .net has nothing to handle what would be handeled by javascript to do a SIMPLE back step on the browser.

So i can even do a Attribute.Add() on a ASPX button control to do what is being done below?
----------------------------------------------------------------------------------------------------
<form style="margin:0px"><input type=button value="< Back to Search Results" class="navigation_objects" onCLick="history.back()"></form>
----------------------------------------------------------------------------------------------------

My issue is thatt he ASPX generaled form tag posts to itself... So i can write code that will make my <asp:button control render like the above. But the click even posts back the same page...

What i am trying to avoid here is having to use nested <form> tags to acomplish a simple back on the browser. From what i am seeing in my search and in this post is that i have to Use a client side script to do this and i have to nest form tags to do this?

I would rather this not become a huge thing of posting values into hidden form fields etc... I honestly can't belive that i can't have a asp:button control post a javascript call that would send the browser backa  page...

Nugs
0
 
NugsAuthor Commented:
I have figure out this issue.

The key is to set the OnMouseDown event of the button rather than the OnClick event fromt he code behind.

So like this:
---------------------------------------------------------------------------------------------------------------------
<asp:Button ID="btnBacktoResults" CausesValidation="false" runat="server" Text="< Back to Search Results" />
...
btnBacktoResults.Attributes.Add("onMouseDown", "javascript: history.back()");
---------------------------------------------------------------------------------------------------------------------

As you can see, no hidden anything, no cleint side form tags nothing fancy... The issue before was that the server side OnClick event was conflicting with the client side or javascript OnClick event.

But i thank you very much for you input, and since you where the only one kind enough to reply to my post - enjoy the points...

Nugs

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now