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 ?

4

3 回答 3

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.

于 2013-04-03T04:52:55.140 回答
0

请参阅http://www.aspdotnet-suresh.com/2012/10/jquery-scroll-to-particular-div.html#middle基于 jquery 的函数,通过 div 正上方的 href 标记滚动到特定 div。您可以在 pageLoad 中添加此功能

于 2013-04-03T04:56:49.597 回答
0

最简单的方法是当用户按下它时有一个链接,它将他滚动到这个 div。

在您的浏览器端,只需<a name="BottomOfThePage"></a>在 div 周围添加。并使链接看起来像这样<a href="#BottomOfThePage">Link</a>

于 2013-04-03T05:00:22.107 回答