How to maintain scroll position on postback?

Last post 07-07-2007, 3:26 PM by fredd. 7 replies.
Sort Posts: Previous Next
  •  07-05-2007, 11:55 PM 31322

    How to maintain scroll position on postback?

    Whenever a postback occurs, the current cursor position is lost and the returned page jumps to the top of the text. How do we maintain the scroll position and the cursor pos on postback?
     
    For example, suppose there are 100 lines in the editor and I'm currently at line 90. When I trigger a postback, the content of the editor starts again at the top instead of scrolling down to line 90 and placing the cursor where it was..
     
    Is there an example?
  •  07-06-2007, 5:46 AM 31328 in reply to 31322

    Re: How to maintain scroll position on postback?

    Hi Fred,
     
    You could use the javascript API to get the scroll position of the iFrame and save it in a hidden field. Use the CuteEditor_OnInitialized event to run a script to set the position back the the saved value.
     
    editor.GetDocument().body.scrollTop is the property you'd be after.
     
    You could probably do something similar for the cursor position through the editor.GetSelection() method.
     
    Ady
  •  07-06-2007, 11:07 AM 31341 in reply to 31328

    Re: How to maintain scroll position on postback?

    Thanks for the info. It's a bit to complex for my small brain but I'll have a look at it.
     
     
  •  07-06-2007, 11:08 AM 31342 in reply to 31322

    Re: How to maintain scroll position on postback?

    Adam, can I please get your reponse on this? It's quite critical. Do you have some code?
  •  07-06-2007, 10:44 PM 31360 in reply to 31342

    Re: How to maintain scroll position on postback?

    fredd,
     
    If you are using asp.net 2.0, please follow the steps below.
     
    1. Download the latest build.
     
    2. In the top of your aspx page, set MaintainScrollPositionOnPostback="true".
     
    Demo:
     
     
    If you are using asp.net 1.1, you need to follow Ady's suggestion and write a piece of JavaScript code.
     
     
     

    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

  •  07-07-2007, 11:24 AM 31369 in reply to 31360

    Re: How to maintain scroll position on postback?

    Thank you for the information. However, we are using .NET V1.1 and I haven't a clue how to write the javascript. Can you please give me some guidance and perhaps some JS example. I have no idea, and it would only take you a few minutes to give me some guidance..

    Our users are screaming about this and I need to resolve it for them.

    Thanks

     

     

     

  •  07-07-2007, 1:02 PM 31371 in reply to 31369

    Re: How to maintain scroll position on postback?

    Hi Fredd,
     
    JavaScript isn't rocket science and is incredibly useful if CuteEditor doesn't have functionality you desire. I've not interfaced with it in this way, but after searching this forum, and a quick read of the API documentation I've managed to come up with the following code.
     
    The reference I gave above will help you if you want to extend this by remembering the highlighted text accross the postback.
     
    Have Fun,
    Ady 
     
    <form id="form1" runat="server">
      <CE:Editor runat="server" ID="oEditor" />
      <asp:HiddenField runat="server" ID="oScrollPos" />
      <asp:Button runat="server" ID="oPostBack" Text="Post Back" />
    </
    form>
    <script type="text/javascript">
    <!--
    //Initialise Reference
    var oEditor = document.getElementById('<%=oEditor.ClientID%>');
    var oField = document.getElementById('<%=oScrollPos.ClientID%>');

    //Set Scroll Position
    if(oEditor.IsReady) CuteEditor_OnInitialized(oEditor);
    function CuteEditor_OnInitialized(editor) {
    editor.GetDocument().body.scrollTop = oField.value;
    }

    //Save Scroll Position
    function PH_PreviousSubmit() {}

    function PH_Submit() {
      oField.value = oEditor.GetDocument().body.scrollTop;
     
    if(PH_PreviousSubmit) {
       
    return PH_PreviousSubmit();
      }
    else {
       
    return true;
      }
    }

    //Intercept form submission and be nice to other events.
    PH_PreviousSubmit = document.forms[0].onsubmit;
    document.forms[0].onsubmit = PH_Submit;
    //-->
    </script>

  •  07-07-2007, 3:26 PM 31373 in reply to 31371

    Re: How to maintain scroll position on postback?

    Thanks, Ady, I'll try. But I really want an answer from tech support as well.
     
    I paid a lot of money for a license for this product and deserve better treatment than I have been getting. The company seems to have only one tech support person and no developers, just Adam, and he appears to be very overworked, in my opinion.
     
    I try to be polite in the messages I write, but time after time, I get no answer, not even the normal courtesy of "we are looking into it" or "we don't have that information".
     
    Instead, the messages just go on ignored. It's very difficult for someone like me who is not a technical expert. I have nowhere to turn for the answers.
     
    Regards,
     
    Fred
     
     
View as RSS news feed in XML