By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,905 Members | 879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,905 IT Pros & Developers. It's quick & easy.

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

P: n/a
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: gregtynd...@gmail.com - view profile
Date: Thurs, Dec 29 2005 11:39 am
Email: gregtynd...@gmail.com
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.scrollTo p;
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.scrol lTop;

}

</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 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.