master pages and scrollTop = 0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey all,
I'm building out my first project using asp.net v2.0 master pages. It seems
that when you use master pages and try to reference document.body.scrollTop
it allways = zero/0. The same code works in a regular .htm file.

Has anyone else seen this?
Anyone know how to get the body.scrollTop property using masterpages.
Thanks for any help
Andy
 
Hi Andy,

Could you show us the master page code? When you view the rendered source,
do you see something different than expected?

Ken
 
Hi Ken,
Here's my master page code:
Thanks for any help

<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="PublicSite.master.cs" Inherits="PublicSite" %>
<%@ Register Src="UserControls/TopNavHome.ascx" TagName="TopNavHome"
TagPrefix="uc2" %>
<%@ Register TagPrefix="cms"
Namespace="Microsoft.ContentManagement.WebControls"
Assembly="Microsoft.ContentManagement.WebControls, Version=5.0.1200.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Register Src="Console/DefaultConsole.ascx" TagName="DefaultConsole"
TagPrefix="uc1" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<cms:RobotMetaTag runat="server"></cms:RobotMetaTag>
<meta name="Description" content="" id="MetaDesc" runat="server" />
<meta name="Keywords" content="" id="MetaKey" runat="server" />
<link href="StyleSheets/PublicSite.css" rel="stylesheet" type="text/css"
/>
</head>
<body onclick="PositionAuthoringConsole();">
<form id="form1" runat="server">
<div id="testdiv">
<table border="0" cellpadding="0" cellspacing="0" width="770"
class="PageBorder">
<tr class="TopNavRow">
<td>
<uc2:TopNavHome ID="TopNavHome1" runat="server" />
<%--TopNavControl--%>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td valign="top" class="LeftNavArea">
<%--SearchControl--%><br />
<%--LeftNavControl--%>
</td>
<td valign="top" class="BodyBox">
<%--PageTitleControl--%>
<span class="Content">
<asp:contentplaceholder
id="BodyContentPlaceHolder" runat="server" />
</span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="Footer">
<%--FooterControl--%>
</td>
</tr>
</table>
<br />
<uc1:DefaultConsole ID="DefaultConsole1" runat="server" />

</div>

</form>

<!-- The following will allow the WBC to autoposition and "float" -->
<script language="javascript" type="text/javascript">

function PositionAuthoringConsole() {
alert("testme: " + window.document.body.scrollTop);


}
</script>
</body>
</html>
 
Hi Andy,

I tried your code and I get zero for the value of the body. What's the
expected value?

What object are you trying to test?

Ken
 
The body.scrollTop value should increase relatively as you scroll down the
page. This should be the relative pixel number to the top of the page.
I use it in our old system to position a MCMS authoring toolbox on the page
(so the toolbox menu floats down the page as the user scrolls down the page)
 
Hey Ken,
Here is a simple sample of how scrollTop should increment as you scroll down
the page. This behavior does not seem to work when using master pages from
what I can see (unless I'm missing something)

Using the relative scrollTop position is the only way I can think of to
position a table/box on the page in a fixed location as the user scrolls down
the page.

Thanks again
Andy


<HTML>
<HEAD><TITLE>Test</TITLE>
</HEAD>
<BODY onscroll="alert(window.document.body.scrollTop);">

..<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 />
..<br />.<br />.<br />.<br />.<br />.<br />.<br />.<br />.<br />.<br />.<br />

</BODY>
</HTML>
 
Hey again (sorry to spam you)
I Keep making baby steps.
I created another static page based on master page - IE view source.
I think the first line of the code is the problem - not sure why though -
this is a line that the framework/visual studio generates.
Any idea on why line one would effect the returned value of
document.body.scrollTop?
Thanks again
Andy

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body onclick="alert(window.document.body.scrollTop);">
<form name="aspnetForm" method="post" action="TestMaster.aspx"
id="aspnetForm">

<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 />
-<br />-<br />-<br />-<br />-<br />-<br />-<br />-<br />-<br />-<br />-<br />


</div>
</form>
</body>
</html>
 
A little more info...
When you create a master page in Visual studio it auto adds the following
line to your master page file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

This line seems to cause problems when trying to access
document.body.scrollTop. Not sure why - when I remove this line from my
master file I can get an accurate value of scrollTop.

Anyone have any ideas?
Thanks
Andy
 
Wow. That's a new one on me. I guess IE is paying attention to something in
the XHTML specification.
 

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

Back
Top