-
scrollToTop and AJAX
Hi all - I'm attempting to have my page automatically scroll to the top when there is an error message to present to the user. Following a tip I found searching, I've enclosed the Javascript scrollTo function in a setTimeout function to avoid a conflict with AJAX remembering the scroll position. Here is the relevant code:
Code:
Private Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
If CType(msgNewInvoice.FindControl("litMessage"), Literal).Text <> "" Then
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "GoToTop", "setTimeout(""window.scrollTo(0, 0)"", 0);", True)
' setTimeout is necessary here because without it AJAX takes priority and will maintain scroll position.
End If
End Sub
This is working fine for me locally, but when I move the code up to our test server, it does not seem to take effect. I have tried increasing the length of the timeout, but no dice. Any ideas on what might different in the test server environment? Thanks for any insight.
-
Re: scrollToTop and AJAX
Is this an ASP.NET question?
-
Re: scrollToTop and AJAX
My mistake. Sorry. :blush:
Can this thread be moved?