 |
|
 |
Hello All,
How to Retain scroll position after postback in asp.net 3.5.
thanks in advance
|
|
|
|
 |
|
 |
This has now been made possible in ASP.NET 2 by putting
maintainScrollPositionOnPostBack=true in the page tag.
It is cross browser too.
Mark
|
|
|
|
 |
|
 |
What you want here is the opposite behavior (MaintainScrollPositionOnPostback=false).
|
|
|
|
 |
|
 |
hi,
Is this possible for any web browser? i write same in page load method but it dose not work in firefox.
help me :(
|
|
|
|
 |
|
 |
Hi,
I noticed that this wasn't working for me, despite implementing it in the correct way. What was happening was that the onscroll function kept setting the the hidden field to 0&0.
After a little further digging, I found that document.body has a more browser friendly version: document.documentElement. Accomodating both can be achieved by:
Math.max(document.body.scrollLeft, document.documentElement.scrollLeft)
Math.max(document.body.scrollTop, document.documentElement.scrollTop)
I amended the OnPreRender method to include this:
'
' OnPreRender. Renders encessary JavaScript code.
'
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
Dim _start As String = "<script language='Javascript'>onscroll = function(){"
_start &= "document.getElementById('" & Me.UniqueID & "').value = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + '&' + Math.max(document.body.scrollTop,document.documentElement.scrollTop)"
_start &= "}</script>"
If Not (Page.IsClientScriptBlockRegistered("start")) Then
Page.RegisterClientScriptBlock("start", _start)
End If
' Move the scrollbar
Dim _goScroll As String = "<script language='javascript'>scrollTo(" & Me.HPos & "," & Me.VPos & ")</script>"
If Not (Page.IsStartupScriptRegistered("goScroll")) Then
Page.RegisterStartupScript("goScroll", _goScroll)
End If
End Sub
Hope this helps someone else!
nezza
-- modified at 10:34 Thursday 17th August, 2006
|
|
|
|
 |
|
 |
I know this post is a little old, and there are a lot of suggestions on code [place here] without explanation of where to put code... The status I've achieved or wrecked with the instructions/posts, is that:
1. Make a class file and insert code.
2. Add class reference above Namespace for page you want to use code.
This is where I get lost, someone said add this:
A. <%@ Register Namespace="AnnulMvtPostBack" TagPrefix="g" Assembly="CHANGE_TO_ASSEMBLY_NAME" %>
-add below first line: [<%@ Page...etc]
B. Writer says he uses [code has returns deleted to save space]:
GetPositionPostBack _GetPositionPostBack = new GetPositionPostBack();
foreach(Control ctrl in Page.Controls){if(ctrl.GetType().Name == "HtmlForm"){ctrl.Controls.Add(_GetPositionPostBack);break;}}
Ok, maybe I'm to new to development, but I usually figure these things out, where do put [B.], is [A.] necessary? Do I need a <script> reference in FORM/do I need to add JavaScript, Do I need to add code to the .cs page that is using the script, or just add code to the .aspx page... If I were to begin after step 2. what else must I do to complete this solution? As you can see I have questions, all I hope for is a clearer path. Specially since a lot of these links don't exist anymore. Any help would be appreciated. Thanks
-- modified at 11:36 Friday 10th March, 2006
|
|
|
|
 |
|
 |
You have to use one of the 2 solutions. In the 2 situations it make the same.
On solution is:
A. <%@ Register Namespace="AnnulMvtPostBack" TagPrefix="g" Assembly="CHANGE_TO_ASSEMBLY_NAME" %>
in the <form> add
<g:AnnulMvtPostBack id="controls" runat="server"/>
or the method B. is also possible!
No need to add javascript the controls make it itself... Just declare it somewhere.
You have to choose
Bye
WebGourou
WebGourou
-- modified at 15:26 Saturday 11th March, 2006
|
|
|
|
 |
|
 |
Great job, this is a great article for peeps that want to offer more cross-browser friendly pages.
I had one comment, though. Maybe "_Restore_ the page scroll position..." would be a better title for the article. When I first saw this I thought it was an article about programmatically disabling SmartNavigation so the page would always scroll back to the top after postback (i.e. the scroll position would be reset).
Just my 2 cents.
Pete
|
|
|
|
 |
|
 |
The control is great, but how do I use it in my Web Application.
The mini tip of "Use as Control" is not so useful.
|
|
|
|
 |
|
 |
Ok, I figured it out. For most of you who are having problems:
1) Put source in your project, as it is.
2) Open your ASPX page, in HTML view.
3) Add this, after the first line:
<%@ Register Namespace="AnnulMvtPostBack" TagPrefix="g" Assembly="_NAME_OF_YOUR_PROJECT_GOES_HERE_" %>
4) Scroll down, and after <form ....> tag put this:
<g:GetPositionPostBack runat="server">
Thats it.. Enjoy
|
|
|
|
 |
|
 |
Seems, I can't display HTML tags in here... I guess this forum doesn't convert them for viewing..
oh well.
go here if you need the tag you need to put in
http://webgourou.europe.webmatrixhosting.net/Webform1.aspx
|
|
|
|
 |
|
 |
Open your WebForm and set the SmartNavigation property to True, or add <@ Page SmartNavigation=true ...
Note however, this will only work on IE.
|
|
|
|
 |
|
 |
As you said smartnavigation only work with IE, contrary as this control.
WebGourou
|
|
|
|
 |
|
 |
Also, smartnavigation always resets the postback state if you use it from a virtual root. In other words, if you have a default.aspx page that uses if(!IsPostback) it will always enter the if statement.
Thanks to this little control you've just made my life a little easier. Thanks
Sooner or later ... Boom!
|
|
|
|
 |
|
 |
Thats what I was going to suggest, a one liner to solve all problems.
|
|
|
|
 |
|
 |
I'd love to use this one-line solution, however, it causes iExplore to crash. I get a 'memory could not be read' error when performing any action on the page. Anyone have any ideas on this?
cheers
|
|
|
|
 |
|
 |
Hello aurel aka WebGourou.
I guess the original article can be seen here :
http://www.aspalliance.com/JimRoss/Samples/MaintainScrollDemo.aspx
Cheers.
|||Cypher|||
|
|
|
|
 |
|
 |
Please tell me how to use your code. Where Place put it.
thankes
bobjeey
from china
|
|
|
|
 |
|
 |
I glad to tell you .
just add following page tag in your aspx file,
<%@ Page SmartNavigation="true" ...
then get the same reult. haha
|
|
|
|
 |
|
 |
Hello smart guy.
You 've just dicovered "smartnavigation", uh ?
The trouble is that does work on IE only.
Unless you wanna be totally alienated to IE browsers / develop an intranet, it is not a recommended solution.
How to implement the code above ?
I guess it is that way :
Page.loadControl(AnnulMvtPostBack.GetPositionPostBack());
BTW : I am not the author of this article, so if you want to have more info on it, write to his author directly (start a new thread).
|||Cypher|||
|
|
|
|
 |
|
 |
Thanks Cypher to help me in this fight !
I use another way to load my Control,
using AnnulMvtPostBack;
GetPositionPostBack _GetPositionPostBack = new GetPositionPostBack();
foreach(Control ctrl in Page.Controls)
{
if(ctrl.GetType().Name == "HtmlForm")
{
ctrl.Controls.Add(_GetPositionPostBack);
break;
}
}
Hope this will help you !
It's not on aspalliance that I've stolen the idea but their code seem to use the same method that mine...
WebGourou
|
|
|
|
 |
|
 |
I use this way to load your control,
but it's not useful,
why?
|
|
|
|
 |
|
 |
I don't understand why it doesn't work, I load this control in this way in my own derived class from System.Web.UI.Page. And I have no problems.
Look at here you will see the difference between a page with a control and a page without(an other way to load the control is used).
http://webgourou.europe.webmatrixhosting.net
WebGourou
|
|
|
|
 |
|
 |
File or assembly name EssaiPostBack, or one of its dependencies, was not found..?
|
|
|
|
 |
|
 |
assembly name "EssaiPostBack"?x.
the assembly name is your project name..
|
|
|
|
 |