measuring web controls height at runtime (or converting .height % to px)

Discussion in 'ASP .Net' started by Wotney, Oct 25, 2006.

  1. Wotney

    Wotney Guest

    Hoping someone out there can help...

    I have an UpdatePanel that uses Atlas/Ajax to update it's contents
    without having to postback the entire page. (pnlUpdate)

    Within pnlUpdate I have a normal panel holding a tree-view control.

    All the controls on my page are dynamic in size. Eg. Height="80%",
    Width = "85%".

    As expected... Upon using the tree-view control... when exposing the
    next level of nodes the control gains in height so it can display the
    new child nodes.

    This is where the problem lies.

    When pnlTreeView increases in size, all the parent controls (the panels
    it sits in) also gain in size. (looks stupid)

    But !

    If I set the pnlTreeView Height to a px value rather than a %... when
    the child nodes are exposed, the control remains the same size and
    displays scrollbars (perfect!)

    Except now it's a fixed size in px, I can't make the treeview expand
    and contract depending on the size of the browser window like all the
    other controls do. (rubbish!)...

    ....So, to get round this I thought I could just set the height of
    pnlTreeView dynamically at run time on the 'Node_Expanded' Sub
    based on the height of it's parent control.

    I set pnlUpdate to Height=85%

    All I want to do is (within code at runtime) is say

    pnlTreeView.Height = pnlUpdate.Height

    (Seems easy enough... BUT)

    Using the above code sets pnlTreeView.height to 85%

    pnlTreeView must have it's height set in pixels, not as a percentage.

    HELP ?
    PLEASE !!

    Cheers guys & gals,

    Wotney, Oct 25, 2006
    1. Advertisements

  2. Set it via Javascript.

    Leave the percentage-based height in place. On page load, read the
    current height of the control in pixels, you can now set the height
    property of the panel to a pixel height, and you're done.

    To get the current height of an element, you have to mutter different
    incantations for different browsers. IIRC prototype.js has a couple of
    functions designed for this purpose, it might be worth a look through
    their source to get the technique.
    Flinky Wisty Pomm, Oct 25, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.