2

In my aspx ,

<div id="commentDiv" runat="server">
<%# Eval("myComment")%>
</div>

At the start of this page loading , I want to auto scroll and navigate to this DIV .
How can i do that ?

  • 1
    Reference this link > http://stackoverflow.com/questions/635706/how-to-scroll-to-an-element-inside-a-div – zey Apr 03 '13 at 04:54

3 Answers3

0

Refer following code:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"
            ScriptMode="Release" />
        <script type="text/javascript">
            var xPos, yPos;
            var param = Sys.WebForms.PageRequestManager.getInstance();
            function BeginRequestHandler(sender, args) {
                if ($get('<%=divMessages.ClientID%>') != null) {
                    xPos = $get('<%=divMessages.ClientID%>').scrollLeft;
                    yPos = $get('<%=divMessages.ClientID%>').scrollTop;
                }
            }
            function EndRequestHandler(sender, args) {
                if ($get('<%=divMessages.ClientID%>') != null) {
                    xPos = $get('<%=divMessages.ClientID%>').scrollLeft = xPos;
                    yPos = $get('<%=divMessages.ClientID%>').scrollTop = yPos;
                }
            }
            param.add_beginRequest(BeginRequestHandler);
            param.add_endRequest(EndRequestHandler);
        </script>

This is important link for this issue:

http://basgun.wordpress.com/2008/06/09/maintain-scroll-position-updatepanel-postback/

Hope its helpful.

Freelancer
  • 9,008
  • 7
  • 42
  • 81
0

See http://www.aspdotnet-suresh.com/2012/10/jquery-scroll-to-particular-div.html#middle jquery based function to scroll to specific div by the href tag, which is right above the div. You can add this function in your pageLoad

Alex
  • 8,827
  • 3
  • 42
  • 58
0

The easiest way is to have a link when the user press on it, it scroll him to this div.

In your browser side just add <a name="BottomOfThePage"></a> around the div. And make the link look like this <a href="#BottomOfThePage">Link</a>

7alhashmi
  • 924
  • 7
  • 24