Click here to Skip to main content
15,900,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have a webpage.In my webpage has scrollbar.
i wanted to set initial scrollbar postion at perticular control on PageLoad.
How can i do this from code behind?
Posted

You can use the javascript as
JavaScript
document.getElementById('MyID').scrollIntoView(true);

or jQuery ScrollTo
http://plugins.jquery.com/project/ScrollTo[^]

Check this How to scroll an ASP.NET control into view after page load using codebehind[^]
 
Share this answer
 
v3
Comments
amit_83 14-Sep-11 5:50am    
Thankx for reply, is there a diffrent way to do from codeehind?
Prerak Patel 14-Sep-11 5:53am    
Updated the answer. Check the article.
amit_83 14-Sep-11 6:18am    
thankx for it.
Prerak Patel 14-Sep-11 6:44am    
You are welcome. Mark answer if your query is solved.
On a postback event that you want the scroll to take place, add this command:

Page.MaintainScrollPositionOnPostBack = false;

And then, set the focus on the control where you want the scroll position to be. For example, if you want the scroll position to be on control "txtName", then you'd add:

this.txtName.Focus();

So alltogether on the event that you don't want to maintain scroll position, you add these two commands:

Page.MaintainScrollPositionOnPostBack = false;
this.txtName.Focus();

That will cancel your maintain scroll position on postback and scroll the page to your control

This is assuming that you set Page.MaintainScrollPositionOnPostBack = true; on PageLoad. Otherwise, simply set Focus to the control that the page needs to scroll to when it comes up.
 
Share this answer
 
v2

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