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 ?
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.
请参阅http://www.aspdotnet-suresh.com/2012/10/jquery-scroll-to-particular-div.html#middle基于 jquery 的函数,通过 div 正上方的 href 标记滚动到特定 div。您可以在 pageLoad 中添加此功能
最简单的方法是当用户按下它时有一个链接,它将他滚动到这个 div。
在您的浏览器端,只需<a name="BottomOfThePage"></a>
在 div 周围添加。并使链接看起来像这样<a href="#BottomOfThePage">Link</a>