Persist ScrollBar's Position After a PostBack
Posted on 2004-07-08 14:29 Dream 阅读(995) 评论(3) 编辑 收藏 举报这个page的参数可以去掉吗?
Public Shared Sub PersistScrollPosition(ByVal page As Page)
Dim saveScrollPosition As System.Text.StringBuilder = New System.Text.StringBuilder
Dim setScrollPosition As System.Text.StringBuilder = New System.Text.StringBuilder
page.RegisterHiddenField("__SCROLLPOS", "0")
saveScrollPosition.Append("<script language='javascript'>")
saveScrollPosition.Append("function saveScrollPosition() {")
saveScrollPosition.Append(" document.forms[0].__SCROLLPOS.value = document.body.scrollTop;")
saveScrollPosition.Append("}")
saveScrollPosition.Append("document.body.onscroll=saveScrollPosition;")
saveScrollPosition.Append("</script>")
page.RegisterStartupScript("saveScroll", saveScrollPosition.ToString())
If page.IsPostBack Then
setScrollPosition.Append("<script language='javascript'>")
setScrollPosition.Append("function setScrollPosition() {")
setScrollPosition.Append(" document.body.scrollTop = " + page.Request("__SCROLLPOS") + ";")
setScrollPosition.Append("}")
setScrollPosition.Append("document.body.onload=setScrollPosition;")
setScrollPosition.Append("</script>")
page.RegisterStartupScript("setScroll", setScrollPosition.ToString())
End If
End Sub