Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
may its a duplicate question what am asking but i want proper solution..

I have a child page with the nested master means 2 master pages inherit one from another..and in that child page i have all user controls only..

so in my case i have maintain scroll position of child page after async post back of user control list box.

i have tried

MaintainScrollPositionOnPostback="true"

with in page directive and js code
XML
<script type="text/javascript" >
           var xPos, yPos;
           var prm = Sys.WebForms.PageRequestManager.getInstance();
           prm.add_beginRequest(BeginRequestHandler);
           prm.add_endRequest(EndRequestHandler);
           function BeginRequestHandler(sender, args) {
               xPos = document.getElementById("<%=Panel1.ClientID %>").scrollLeft;
               yPos = document.getElementById("<%=Panel1.ClientID %>").scrollTop;
           }
           function EndRequestHandler(sender, args) {
               document.getElementById("<%=Panel1.ClientID %>").scrollLeft = xPos;
               document.getElementById("<%=Panel1.ClientID %>").scrollTop = yPos;
           }
 </script>

for panel and for div and update panel..these all are fails completely, why because if child page is getting post back means the related master pages also post backed..but i don't know how to maintain the scroll position..

try to help me as soon as possible..

thanks guys
Posted
Updated 28-Apr-14 4:38am
v3

1 solution

Hi Sharath.Mitte! xPos and yPos are javascript variables and they disappear on postback. You'll need to save in a hidden field.

Assuming you have an <asp:hiddenfield id="hid" runat="server"/>

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = document.getElementById("<%=Panel1.ClientID %>").scrollLeft;
yPos = document.getElementById("<%=Panel1.ClientID %>").scrollTop;
var h = document.getElementById("<%=hid.ClientID %>");
h.value = xPos.toString() + "_" + yPos.toString();
}
function EndRequestHandler(sender, args) {
var val = document.getElementById("<%=hid.ClientID %>").value.split('_');
xPos = parseFloat(val[0]);
yPos = parseFloat(val[1]);
document.getElementById("<%=Panel1.ClientID %>").scrollLeft = xPos;
document.getElementById("<%=Panel1.ClientID %>").scrollTop = yPos;


}
Regards
 
Share this answer
 
Comments
Sharath.Mitte 28-Apr-14 10:24am    
Hi,<br>
Thanks for Quick reply, now i got it little more..works fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900