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

Make a user control floatable?

P: n/a
Hi,

I have a user control which I use on all my pages. The control is situated
on the top of my page (sits on my master page).

For some long pages the user has to scroll back up to the top of the page to
select an option from my user control.

Can I make this user control floatable so that as the user scrolls down the
page the user control moves down also?

Any info appreciated.

Thanks.

May 31 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Yes,

search for floating div

Put your UC in a div (or the panel), then you basically use DHTML to allow
it to move.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"C" <C@discussions.microsoft.comwrote in message
news:3E**********************************@microsof t.com...
Hi,

I have a user control which I use on all my pages. The control is situated
on the top of my page (sits on my master page).

For some long pages the user has to scroll back up to the top of the page
to
select an option from my user control.

Can I make this user control floatable so that as the user scrolls down
the
page the user control moves down also?

Any info appreciated.

Thanks.

May 31 '07 #2

P: n/a
To explain David's answer a bit:

You use CSS absolute positioning to position a div (or "Panel") that is not
nested in any other element or Control, so that in the HTML it is a child of
the document or form (the form has no effect on positioning). This makes its
position relative to the HTML document itself. You can then position it
using a combination of CSS "left", "top", "right" and/or "bottom" styles
absolutely relative to the document.

Your next problem, of course, is that the document is often larger than the
browser window or ViewPort. If so, the element may be positioned outside of
the ViewPort, such as an element that is positioned at the top of the
document, when the document is scrolled down.

This requires the use of JavaScript to solve (JavaScript + HTML = DHTML).
You have to get the position relative to the top of the window. Fortunately,
the HTML DOM element document.documentElement has a "scrollTop" and
"scrollLeft" property, which indicates the distance from the top/left of the
document and the top/left of the window. So, if you want to position your
element at, say, 20 px down from the top of the window, and 20 pixels to the
right of the left edge of the window, you add 20 to
document.documentElement.scrollTop to get the "top" position style and 20 to
document.documentElement.scrollLeft to get the "left" position.

However, you're not done yet. CSS styles are strings which include the
measuring unit. The pixel measuring unit is "px" - so, you use JavaScript to
concatenate the number to the string "px" to get something like "20px".
JavaScript Example:

function setInfoDiv(x, y)
{
var el = document.getElementById("infoDiv");
var xOffset = x + document.documentElement.scrollLeft;
var yOffset = y + document.documentElement.scrollTop;
el.style.left = xOffset + "px";
el.style.top = yOffset + "px";
}

Now you still have one hurdle to jump. What happens when the document is
scrolled, up, down, left or right? You have to use JavaScript to handle the
"scroll" event of the document. for this, you create an event handler
function that takes 1 argument, an event. You can use this to call the
function above. Example (compatible with IE and FireFox):

function handleScroll(e)
{
setInfoDiv(20, 20);
}
document.onscroll = handleScroll;

Here are a couple of resources that may help:

http://www.quirksmode.org/resources.html
http://developer.mozilla.org/en/docs/DOM:element

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:OT**************@TK2MSFTNGP05.phx.gbl...
Yes,

search for floating div

Put your UC in a div (or the panel), then you basically use DHTML to allow
it to move.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"C" <C@discussions.microsoft.comwrote in message
news:3E**********************************@microsof t.com...
>Hi,

I have a user control which I use on all my pages. The control is
situated
on the top of my page (sits on my master page).

For some long pages the user has to scroll back up to the top of the page
to
select an option from my user control.

Can I make this user control floatable so that as the user scrolls down
the
page the user control moves down also?

Any info appreciated.

Thanks.


May 31 '07 #3

P: n/a
You could just use the free AlwaysVisible control:
http://ajax.asp.net/ajaxtoolkit/Alwa...leControl.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"C" <C@discussions.microsoft.comwrote in message
news:3E**********************************@microsof t.com...
Hi,

I have a user control which I use on all my pages. The control is situated
on the top of my page (sits on my master page).

For some long pages the user has to scroll back up to the top of the page
to
select an option from my user control.

Can I make this user control floatable so that as the user scrolls down
the
page the user control moves down also?

Any info appreciated.

Thanks.
May 31 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.