i have a GridView inside the UpdatePanel and after every Submit button click the screen flashes and jumps to the top of the page. i then have to scroll back down to see the results of the query.
has anyone found a way to save the location of the page in codebehind, then reload the scroll position to where original submit query was initiated on the page?
i found a few javascript options, but i am looking for an asp.net/vb.net solution.
thank you, unfortunately from what i read in the long thread is that the suggestions provided are javascript-based. i am looking for a non-javascript solution. any ideas using asp.net/vb.net?
suppose your update panel is on a div with id DataDiv call a script from the div
<div id="DataDiv"onscroll="Onscrollfnction()">
and the script is
<script language="javascript" type="text/javascript">
function Onscrollfnction()
{
var div = document.getElementById('DataDiv');
var s=document.getElementById("DataDiv").scrollTop;
var input = document.getElementById("hdnScrollTop");
input.setAttribute("value", s);
document.getElementById("aspnetForm").appendChild(input);
return false;
}
</script>
and now add anothe script to get the position on postback
<script language="javascript" type="text/javascript">
function ScrolPosition(DataDiv,hdnScrollTop){
var hdnFld=document.getElementById(hdnScrollTop);
if(hdnFld!=null)
{
document.getElementById(DataDiv).scrollTop =document.getElementById(hdnScrollTop).value;
}
}
</script>
many, many thanks for this suggestion, however, i am looking for a solution that does not use any javascript. i am not sure if it is possible, but thought i would ask.
Usually People loves to maintain the scroll postiion. But requirment is reverse, Here is the trick, create an script tag after the scriptmanager and put the following lines:
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(beginRequest);
function beginRequest()
{
prm._scrollPosition = null;
}
</script>
even though all these options use javascript, i tried each one with the following results. i am using master pages so, i placed the javascript code just above </asp:Content> tag in the content page. ScriptManager loads at the top of the Site.Master page.
these two links are the same solution, located at different sites. the page posts to the top of the page after a partial postback.
the best option so far is to simply use the web.config option. the position on the page is maintained after a partial postback, however, the page flashes (flickers) badly after the asynchronous postback. if i can find a fix for the flicker, i will have
a complete solution. thanks to everyone, but still looking.
philos
Member
8 Points
36 Posts
how to maintain scroll position with UpdatePanel
Aug 11, 2012 01:47 AM|LINK
hello,
i have been trying to find a good way to maintain the scroll position on a page after an UpdatePanel async postback. i tried a couple options:
and the web.config method:
but neither works.
i have a GridView inside the UpdatePanel and after every Submit button click the screen flashes and jumps to the top of the page. i then have to scroll back down to see the results of the query.
has anyone found a way to save the location of the page in codebehind, then reload the scroll position to where original submit query was initiated on the page?
i found a few javascript options, but i am looking for an asp.net/vb.net solution.
thanks!
scroll updatepanel
ganesh.rane
Participant
1854 Points
318 Posts
Re: how to maintain scroll position with UpdatePanel
Aug 11, 2012 05:25 AM|LINK
Check this
http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx
scroll updatepanel
Ganesh Rane
Don't forget to mark useful responses as Answer if they helped you towards a solution.
philos
Member
8 Points
36 Posts
Re: how to maintain scroll position with UpdatePanel
Aug 11, 2012 06:06 AM|LINK
thank you, unfortunately from what i read in the long thread is that the suggestions provided are javascript-based. i am looking for a non-javascript solution. any ideas using asp.net/vb.net?
scroll updatepanel
ajvadrahman
Member
62 Points
11 Posts
Re: how to maintain scroll position with UpdatePanel
Aug 11, 2012 06:15 AM|LINK
place ahidden input on your page
suppose your update panel is on a div with id DataDiv call a script from the div
and the script is
<script language="javascript" type="text/javascript"> function Onscrollfnction() { var div = document.getElementById('DataDiv'); var s=document.getElementById("DataDiv").scrollTop; var input = document.getElementById("hdnScrollTop"); input.setAttribute("value", s); document.getElementById("aspnetForm").appendChild(input); return false; } </script>and now add anothe script to get the position on postback
<script language="javascript" type="text/javascript"> function ScrolPosition(DataDiv,hdnScrollTop){ var hdnFld=document.getElementById(hdnScrollTop); if(hdnFld!=null) { document.getElementById(DataDiv).scrollTop =document.getElementById(hdnScrollTop).value; } } </script>register the script on page load
ClientScript.RegisterStartupScript(this.GetType(), "ScrolPosition", "<script>ScrolPosition('DataDiv','ctl00_cphMain_hdnScrollTop');</script>");"ctl00_cphMain_hdnScrollTop" is the hidden feild running id make the corresponding changes in your id and run it safely
scroll updatepanel
philos
Member
8 Points
36 Posts
Re: how to maintain scroll position with UpdatePanel
Aug 11, 2012 06:38 AM|LINK
many, many thanks for this suggestion, however, i am looking for a solution that does not use any javascript. i am not sure if it is possible, but thought i would ask.
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: how to maintain scroll position with UpdatePanel
Aug 13, 2012 03:31 AM|LINK
<script type="text/javascript"> var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_beginRequest(beginRequest); function beginRequest() { prm._scrollPosition = null; } </script>http://disturbedbuddha.wordpress.com/2007/12/03/maintain-scroll-position-after-asynchronous-postback/
http://anildiggiwal.blogspot.in/2011/09/maintain-gridview-scroll-position-and.html
http://basgun.wordpress.com/2008/06/09/maintain-scroll-position-updatepanel-postback/
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
teguhyuliant...
Participant
1370 Points
372 Posts
Re: how to maintain scroll position with UpdatePanel
Aug 13, 2012 07:24 AM|LINK
Here the additional reference for you about how to maintain scroll position with update panel :
http://stackoverflow.com/questions/5288682/maintain-panel-scroll-position-on-partial-postback-asp-net
philos
Member
8 Points
36 Posts
Re: how to maintain scroll position with UpdatePanel
Aug 17, 2012 01:24 AM|LINK
even though all these options use javascript, i tried each one with the following results. i am using master pages so, i placed the javascript code just above </asp:Content> tag in the content page. ScriptManager loads at the top of the Site.Master page.
http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx
result: the page posts to the top of the page after a partial postback.
http://disturbedbuddha.wordpress.com/2007/12/03/maintain-scroll-position-after-asynchronous-postback/
the page posts to the top of the page after a partial postback.
http://anildiggiwal.blogspot.in/2011/09/maintain-gridview-scroll-position-and.html
the page posts to the top of the page after a partial postback.
http://basgun.wordpress.com/2008/06/09/maintain-scroll-position-updatepanel-postback/
http://stackoverflow.com/questions/5288682/maintain-panel-scroll-position-on-partial-postback-asp-net
these two links are the same solution, located at different sites. the page posts to the top of the page after a partial postback.
the best option so far is to simply use the web.config option. the position on the page is maintained after a partial postback, however, the page flashes (flickers) badly after the asynchronous postback. if i can find a fix for the flicker, i will have a complete solution. thanks to everyone, but still looking.
scroll updatepanel