This article mainly introduces the problem of resolving the position reset of div scroll bar after asp.net return, the central idea is to save the current Scorll value with a hidden control. Return the value based on the scrolltop, then reset the scrolltop in Page_Load;
The first is to add a onscroll= "Javascript:setscolltop ()" Method for the DIV (not necessarily the div other tag mentality should be the same) code as follows: <div style= "overflow: Auto height:152px "align=" left "id=" Dvscoll_1 " onscroll=" Javascript:setscolltop () "> Www.jb51.net ... </div > Here the Setscrolltop method is to assign the scrolltop value of a div to a hidden control each time the scroll bar scrolls. Code as follows code as follows: function Setscolltop () { document.getelementbyid ("<%= Hidscrolltop.clientid%> "). Value=document.getelementbyid (" Dvscoll_1 "). scrolltop; } because each. NET postback scroll bar is reset, we have scrolltop the div in Page_Load. The code is as follows code as follows: if (! IsPostBack) { &NB Sp ..... Else &NB Sp { /recoveryScroll bar position if (this.hidscrolltop.value!= "") { String scrolltop = This.hidScrollTop.Value; string strscript= "Document.getelementb Yid (' Dvscoll_1 '). scrolltop= "+scrolltop; Registerscriptblock (this. Page, Strscript); & nbsp } The Registerscriptblock here is a method I write in a common class library, as shown below. Code as follows: ///<summary> ///registration script block ///</summary> Pub Lic static void Registerscriptblock (System.Web.UI.Page Page, string _scriptstring) { page. Clientscript.registerstartupscript (page. GetType (), "Scriptblock", "<script type= ' Text/javascript ' >" + _scriptstring + "</script>"); }