Saturday, January 15, 2011

Maintaine Scroll Position After PostBack For Partial Page in Asp.Net(Using Div)

0 comments 1/15/2011
Sign up to receive our site updates!
Some times our page contains scrollable division inside the page,In last article i disused about Maintain Scroll Position After PostBack in Page Level , But it maintains scroll position for page level only not inside.


For This to achieve we need to take two hidden fields to store scroll position in between postbacks

First add the following javascript code in head section of page...






<script type="text/javascript">
var hid1,hid2;
function SetDivPosition()
{
hid1=$get('<%=HiddenField1.ClientID %>');
hid2=$get('<%=HiddenField2.ClientID %>');
hid1.value=$get('<%=divScroll.ClientID %>').scrollLeft;
hid2.value=$get('<%=divScroll.ClientID %>').scrollTop;
}
function GetPosition()
{
hid1=$get('<%=HiddenField1.ClientID %>');
hid2=$get('<%=HiddenField2.ClientID %>');
$get('<%=divScroll.ClientID %>').scrollLeft=hid1.value;
$get('<%=divScroll.ClientID %>').scrollTop=hid2.value;

script>

Add function on body onload event

<body onload ="GetPosition();">

Add Div code as follows

  <div id="divScroll" onclick="SetDivPosition();" style="width:200px; height:400px; overflow:auto;">
Your Code Goes here..
.
.
.
.


<div>
Your Ad Here

0 comments:

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri