The first is to add a onscroll= "Javascript:setscolltop ()" Method for the Div (not necessarily div other tagging ideas should be the same)
Copy Code code as follows:
<div style= "Overflow:auto; height:152px "align=" left "id=" Dvscoll_1 "onscroll=" Javascript:setscolltop () ">
Www.jb51.net
......
</div>
The Setscrolltop method here is to assign the scrolltop value of a div to a hidden control each time the scroll bar scrolls. The code is as follows
Copy Code code as follows:
function Setscolltop ()
{
document.getElementById ("<%=hidScrollTop.ClientID%>"). Value=document.getelementbyid ("Dvscoll_1"). scrolltop;
}
Because every. NET postback scroll bar is reset, here we Page_Load the DIV's scrolltop in the back of the text. The code is as follows
Copy Code code as follows:
if (! IsPostBack)
{
。。。。。
}
Else
{
Restore scroll bar position
if (this.hidscrolltop.value!= "")
{
string scrolltop = This.hidScrollTop.Value;
String strscript= "document.getElementById (' Dvscoll_1 '). scrolltop=" +scrolltop;
Registerscriptblock (this. Page, Strscript);
}
}
The Registerscriptblock here is a method I wrote in a common class library, as shown below.
Copy Code code as follows:
<summary>
Registering script blocks
</summary>
public static void Registerscriptblock (System.Web.UI.Page Page, String _scriptstring)
{
Page. Clientscript.registerstartupscript (page. GetType (), "Scriptblock", "<script type= ' Text/javascript ' >" + _scriptstring + "</script>");
}