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

B

bluegrasslover

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: (e-mail address removed) - view profile
Date: Thurs, Dec 29 2005 11:39 am
Email: (e-mail address removed)
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top