如何在单击WEB控件引发页面刷新时定位页面?(不使用智能导航)

80酷酷网    80kuku.com

  web|控件|刷新|页面1.函数(参考其它网友,有作变动)


#Region "防止页面滚动"
Private Function RetainScrollPosition()
Dim saveScrollPosition As StringBuilder = New StringBuilder
Dim setScrollPosition As StringBuilder = New StringBuilder

RegisterHiddenField("__SCROLLPOS", "0")

saveScrollPosition.Append("<script language='javascript'>")
saveScrollPosition.Append("function saveScrollPosition() {")
saveScrollPosition.Append(" document.forms[0].__SCROLLPOS.value = mybody.scrollTop;")
saveScrollPosition.Append("}")
saveScrollPosition.Append("mybody.onscroll=saveScrollPosition;")
saveScrollPosition.Append("</script>")

RegisterStartupScript("saveScroll", saveScrollPosition.ToString())

If (Page.IsPostBack) Then
setScrollPosition.Append("<script language='javascript'>")
setScrollPosition.Append("function setScrollPosition() {")
setScrollPosition.Append(" mybody.scrollTop = " & Request("__SCROLLPOS") & ";")
setScrollPosition.Append("}")
setScrollPosition.Append("mybody.onload=setScrollPosition;")
setScrollPosition.Append("</script>")

RegisterStartupScript("setScroll", setScrollPosition.ToString())
End If
End Function
#End Region


2.调用


在page_load事件中调用RetainScrollPosition()


3.其它


将<body>的id命名为“mybody”


分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: