470,596 Members | 1,528 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

master pages and scrollTop = 0

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
May 16 '06 #1
9 3815
Hi Andy,

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

Ken

"Andy" <An**@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
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

May 17 '06 #2
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>
"Ken Cox [Microsoft MVP]" wrote:
Hi Andy,

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

Ken

"Andy" <An**@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
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


May 17 '06 #3
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
"Andy" <An**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
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>
"Ken Cox [Microsoft MVP]" wrote:
Hi Andy,

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

Ken

"Andy" <An**@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
> 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


May 17 '06 #4
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)

"Ken Cox [Microsoft MVP]" wrote:
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
"Andy" <An**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
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>
"Ken Cox [Microsoft MVP]" wrote:
Hi Andy,

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

Ken

"Andy" <An**@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
> 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


May 17 '06 #5
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>
May 17 '06 #6
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>
May 17 '06 #7
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

"Andy" wrote:
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

May 17 '06 #8
check this out.

http://www.vbforums.com/showthread.php?t=386200

SA
"Andy" <An**@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
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

"Andy" wrote:
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

May 17 '06 #9
Wow. That's a new one on me. I guess IE is paying attention to something in
the XHTML specification.

"Andy" <An**@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
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>

May 17 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Michael Herman \(Parallelspace\) | last post: by
17 posts views Thread by Rob R. Ainscough | last post: by
3 posts views Thread by Rich | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.