SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Scroll Issue Please Help

    Hi All:

    I have a slight problem with my asp.net application (Javascript problem) and was wondering if you could help me out.

    I have an asp.net ajax application which refreshes messages every 7 seconds via a timer control. I have a literal control wrapped in a div tag which grabs new messages from my sql server database via asp.net ajax. Now in IE, everytime the page refreshes, I have a javascript function which allows the scrollbars of the div to be placed all the way at the bottom, so that the user does not have to rescroll down to the bottom of the div every 7 seconds.. The following is the javascript function that does so (it works..)

    function ScrollOnRefresh() {
    var element = document.getElementById("MessagesDiv");
    element.scrollTop = 1000000000;
    }

    This function will not work in Firefox at all, could someone please help me with the work around for firefox that places the scrollbar all the way to the bottom of the messagesdiv.


    thank you,
    aspdev

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2008
    Location
    Dublin, Ireland
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried setting MaintainScrollPositionOnPostback="true" for the page?

    If that doesn't do what you want the general way to scroll a page is window.scroll(x, y); and window.scoll(0, element.style.top + element.offsetHeight); may work but you should have a look at quirksmode on the position of an element and the dimensions of an element so as to develop a proper cross browser solution.

  3. #3
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brian:

    Would I set MaintainScrollPositionOnPostback on the <div> element? or in the Page directive?

    Thanks for your prompt reply, I really appreciate it..

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2008
    Location
    Dublin, Ireland
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was referring to the page directive but it may not work as intended if you are using microsoft's rather horrible ajax stuff so window.scroll may be the way to go.

  5. #5
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im talking about scrolling the <div> element.. not the actual browser window... the maintainscroll does not work...

  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2008
    Location
    Dublin, Ireland
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try element.scroll(x,y) then instead of the window.scroll suggestion.


Bookmarks

Posting Permissions

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