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

发表于:2007-06-30来源:作者:点击数: 标签:
1.函数(参考其它网友,有作变动) #Region 防止页面滚动 Private Function RetainScrollPosition() Dim saveScrollPosition As StringBuilder = New StringBuilder Dim setScrollPosition As StringBuilder = New StringBuilder RegisterHiddenField(__SCROLLP
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”


原文转自:http://www.ltesting.net