Results 1 to 3 of 3

Thread: scrollToTop and AJAX

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    4

    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.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: scrollToTop and AJAX

    Is this an ASP.NET question?

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    4

    Re: scrollToTop and AJAX

    My mistake. Sorry.

    Can this thread be moved?
    Last edited by Straadin; Sep 10th, 2010 at 11:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width