Scroll to top of the page on postback

Last post 06-05-2007, 11:07 PM by Adam. 5 replies.
Sort Posts: Previous Next
  •  05-18-2007, 7:13 PM 29822

    Scroll to top of the page on postback

    Hello,
    It seems that Cute Editor control resets page scroll position back to the top after a postback. I'm using "CuteEditor.dll" v6.0.0.0 (CuteEditor 6.0 Build 2007-05-10). I have tracked the issue down to "CuteEditorImplementation.js" (this "js" is accessed from "LoadXMLAsync" function in "Loader.js", if this helps...)
    I have following JScript to control page position after postbacks:
     
     
    <script language='javascript'>      
    function SetScrollLocation() {        
       document.body.scrollTop = ...this value is set in the code-behind during the postback, based on the value of
                                            "__SCROLL_POSITION" element at the time of the postback;    
    }                
    document.body.onload = SetScrollLocation;      
                  
    function SaveScrollLocation() {           
       document.forms[0].__SCROLL_POSITION.value = document.body.scrollTop; 
    }                  
    window.onscroll = SaveScrollLocation;         
    </script>
     
     
    This issue sems to be identical to the problem in the following thread, but no resolution was suggested (http://cutesoft.net/forums/thread/17871.aspx)
     
    Yevgeniy
  •  05-22-2007, 9:08 PM 29936 in reply to 29822

    Re: Scroll to top of the page on postback

    Yevgeniy,
     
    Can you put your JavaScript together, create an example aspx which can demonstrate the problem and send it to me?
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  06-05-2007, 4:13 PM 30403 in reply to 29936

    Re: Scroll to top of the page on postback

    Hello Adam,
    Here is the code to demonstrate the problem. If the "Cute Editor" control is removed from the page, the scroll position is maintained. However, with the "Cute Editor" control on the page, the scroll position is reset to the top (sometimes after jumping up/down a few times).
     
    <!--
    <%@ Page language="c#"%>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>

    <script runat="server" language="C#">
     void Page_Load(object sender, EventArgs e)
     {
      //SET/RESTORE scroll position
      string lastPosition = "0";
      if (IsPostBack) {
       lastPosition = Request.Form["__SCROLL_POSITION"];
      }
      
      //register hidden field on the page (will keep last position)
      RegisterHiddenField("__SCROLL_POSITION", lastPosition);
     }
    </script>

    <script language="javascript">
     //SET scroll position
     function SetScrollLocation() {
      document.body.scrollTop = document.forms[0].__SCROLL_POSITION.value;
     }
     //call function when "onLoad" fires
     window.onload = SetScrollLocation;
     
     
     //SAVE scroll position
     function SaveScrollLocation() {
      document.forms[0].__SCROLL_POSITION.value = document.body.scrollTop;
     }
     //call function when scrolling
     window.onscroll = SaveScrollLocation;
    </script>


    <html>
     <body>

      <form id="Form1" method="post" runat="server">
      
       <div style="height:700px">
        <span style="color:red;">TOP of the Page</span><br/>
        This is just a placeholder that takes up space on the page
       </div>
       <div style="height:400px;">
        This is another placeholder, but it contains a button to trigger a postback<br/>
        <asp:Button ID="MyButton" Runat="server" Text="Scroll and then click me"></asp:Button>
       </div>
      
       <!-- "Cute Editor" control -->
       <CE:Editor id="Editor" runat="server" ConfigurationPath="~/CuteSoft_Client/CuteEditor/Configuration/AutoConfigure/full.config"
          AutoParseClasses="false" Focus="false">
       </CE:Editor>

      </form>

     </body>
    </html>
    -->
  •  06-05-2007, 4:20 PM 30405 in reply to 30403

    Re: Scroll to top of the page on postback

    Yevgeniy,
     
    This issue has been reported before.
     
    We believe we fixed it.
     
    Can you download the latest build and try again?
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  06-05-2007, 6:26 PM 30407 in reply to 30405

    Re: Scroll to top of the page on postback

    Adam,
    Looks like the problem still exists (at least for IE 6/7). I just downloaded the latest Cute Editor version available (CuteEditor 6.0 Build 2007-05-21), but get the same jump to the top of the page. I can see that my JScript code restores the position, but then the page jumps to the top. It seems that control keeps loading after the page has rendered -- the control generates an XMLHttpRequest in "LoadXMLAsync" function in "Loader.js" and after the response comes back, the page scrolls to the top.
     
    You can test the issue with the code I provided above. The code can be saved as an "aspx" page (no code-behind required).
     
    Yevgeniy
  •  06-05-2007, 11:07 PM 30411 in reply to 30407

    Re: Scroll to top of the page on postback

    Hi Yevgeniy,


    Please change:
     
    window.onload = SetScrollLocation;
     
    to:
     
     window.onload = setTimeout(SetScrollLocation,1000);

    Then test again.
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML