Solving the problem of position reset of div scroll bar after asp.net return

Source: Internet
Author: User
Tags net return reset

  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>");    }  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.