SOLUTION: Body onscroll, scrollTop, scrollLeft not working with master pages ???

Discussion in 'ASP .Net' started by bluegrasslover@gmail.com, Nov 25, 2006.

  1. Guest

    I've gotten a couple of emails about this problem lately so I'm going
    to post the solution that someone emailed me a while back.

    When you create a master page visual studio automatically adds a <--
    doctype ... statement near the top of the master page.
    Somehow this forces some w3c standard where scrolltop isn't supported.
    I removed the doctype declaration from my masterpage and everything
    works fine.
    Actually I changed the dtd type to something else less strict - don't
    have the code in front of me.



    From: - view profile
    Date: Thurs, Dec 29 2005 11:39 am
    Email:
    Groups: microsoft.public.dotnet.framework.aspnet
    Not yet rated
    Rating:
    show options
    Reply | Reply to Author | Forward | Print | Individual Message | Show
    original | Report Abuse | Find messages by this author

    I have a weird problem. I'm using a master page to hold a menu that I
    want to scroll as the user scrolls in the browser window so it will
    always be visible. First off, putting onsroll in the body tag of my
    master page does nothing. Oh, IE is the browser.

    <body onscroll="alert('scrolling')">

    I was able to get around this setting an event hander for
    window.onscroll. However, body.scrollTop is always 0! I wrote a plain
    aspx test file to make sure I wasn't losing my mind and it worked
    perfectly. Here is the code for the test file...
    .....
    <script language="javascript">
    function movediv()
    {
    //document.all.div1.style.top=document.body.scrollTop;
    alert(document.body.scrollTop);
    }

    </script>
    </HEAD>

    <body onscroll="movediv()">
    <form id="Form1" method="post" runat="server">
    <div id="div1" style="position:absolute">This is a
    div</div>
    <br /><br /><br /><br /><br /><br /><br /><br /><br
    /><br /><br
    />
    <br /><br /><br /><br /><br /><br /><br /><br /><br
    /><br /><br
    />
    <br /><br /><br /><br /><br /><br /><br /><br /><br
    /><br /><br
    />
    <br /><br /><br /><br /><br /><br /><br /><br /><br
    /><br /><br
    />
    <br /><br /><br /><br /><br /><br /><br /><br /><br
    /><br /><br
    />
    <br /><br /><br /><br /><br /><br /><br /><br /><br
    /><br /><br
    />
    <br /><br /><br /><br /><br /><br /><br /><br /><br
    /><br /><br
    />
    <br /><br /><br /><br /><br /><br /><br /><br /><br
    /><br /><br
    />
    </form>
    </body>
    </HTML>

    In my .master page I'm basically doing this

    .....
    <body>
    <table>
    <tr>
    <td>
    <div id="divMenu" style="position:absolute">menu buttons
    here</div>
    </td>
    <td>
    <asp:contentplaceholder ....
    </td>
    </tr>
    </table>

    <script language=javascript>
    window.onscroll=scrolldiv;

    function scrolldiv()
    {
    document.all.divMenu.style.top=document.body.scrollTop;

    }

    </script>

    body.scrollTop is always 0!!! I checked scrollLeft and it is always 0
    as well! I also tried adding a button that just alerts the scrolltop
    value which is also 0. And yes, I the page was scrolled down so 0 is
    an invalid value.

    I've been searching for an answer to this for hours and have found
    nothing. Does anyone have a clue?

    TIA,
    Greg
     
    , Nov 25, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    5,884
  2. =?Utf-8?B?QW5keQ==?=

    master pages and scrollTop = 0

    =?Utf-8?B?QW5keQ==?=, May 17, 2006, in forum: ASP .Net
    Replies:
    9
    Views:
    3,363
    Ken Cox [Microsoft MVP]
    May 17, 2006
  3. Replies:
    0
    Views:
    681
  4. London Boy
    Replies:
    2
    Views:
    334
    Keith Bowes
    Jan 12, 2004
  5. MadMad
    Replies:
    2
    Views:
    155
    MadMad
    Jul 3, 2007
Loading...

Share This Page