CSS Expression statements so set width

5 posts, 0 answers
  1. czone
    czone avatar
    6 posts
    Member since:
    Jun 2005

    Posted 26 May 2007 Link to this post

    I'm working with a RadDocZone and I'd like to use an expression to set the width of the zone programmatically.

    I know this code won’t work but thought if I showed it to you it would be easier to understand what I’m trying to accomplish.

    RadDockZone rzone1 = new RadDockZone();

    rzone1.ID = "zone1";

    rzone1.Width = expression(document.body.clientWidth-438);

    The issue is that I get a compile error because "expression" and "document" are not valid.  The expression statement works fine when I use it in a CSS file.

    However, for other reasons, I have to set the width programmatically; I can't use a CSS file.  So using the expression statement in a CSS file isn't an option.

    Is there any way I can set the Width property for a RadDocZone in my server code so that it will be sized dynamically on the client?

    Thanks in advance for any help!

  2. Petya
    Admin
    Petya avatar
    869 posts

    Posted 28 May 2007 Link to this post

    Hello,

    You can achieve the desired result by adding the following style to the head tag:

    <head>
        <title>Untitled Page</title>
        <style type="text/css">
        #<%= RadDockZone1.ClientID %>
        {
            width: expression(document.body.clientWidth - 438);
        }
        </style>
    </head>

    In this way you modify the width of a particular RadDockZone with id = RadDockZone1.

    To modify the width of all zones, override RadDockZone_[Used Skin] class:

    <head>
        <title>Untitled Page</title>
    <style type="text/css">
        .RadDockZone_Default
        {
            width: expression(document.body.clientWidth - 438);
        }
        </style>
    </head>

    Hope this helps.

    Kind regards,
    Petya
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. czone
    czone avatar
    6 posts
    Member since:
    Jun 2005

    Posted 28 May 2007 Link to this post

    Petya,
    Thank you for the response. However it doesn't meet my requirement.  Due to a list of business requirements that are too long to share, I have to set the width property in my code behind file and not in my aspx file.

    I did forget to metion that in my initial post the 438 is only an example and this number will be dynmaic and determined in the code behind file.  So I can't hard code it in the aspx page & this is why I need to set the width value to

    I've tried the following and while they both compile, neither of them work.

    Example 1:
    rzone2.Style.Add("width", "expression(document.body.clientWidth-400px)");

    Example 2:
    rzone2.Style["width"] = "expression(document.body.clientWidth-400" + "px)";

    On both cases rzone2 is RadDocZone object.

    Essentially what I'm trying to do is dynamically build a page that has three RadDocZones with two of them having a fixed width and the third needs to be fluid and take up the entire window. In other cases I may only have two RadDocZones so I can't rely on anything being known up front and all info, like number of zones needed will come from the database.

    Thanks in advance for any help!

  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 04 Jun 2007 Link to this post

    Hi czone,

    You could use inline script elements in the style:
    <head>
        <title>Untitled Page</title>
        <style type="text/css">
        #<%= RadDockZone1.ClientID %>
        {
            width: expression(document.body.clientWidth - <%= WidthOffset %>);
        }
        </style>
    </head>

    where WidthOffset is declared in the page code-behind:

    public int WidthOffset = 500;

    Let me know if this works for you.

    Regards,
    Valeri Hristov (Senior Developer, MCSD)
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. czone
    czone avatar
    6 posts
    Member since:
    Jun 2005

    Posted 04 Jun 2007 Link to this post

    Thanks for the response.  I figured out how to accomplish what I needed to do another way.  I'm able to do the following in my code behind file and it meets my needs. Here's the code......

    RadDockZone rzone2 = new RadDockZone();  // Creates the zone

    rzone2.ID = "Zone2";  // Set the id for the zone

    rzone2.Style.Add(HtmlTextWriterStyle.Width, "expression(document.body.clientWidth-438+'px')");  // Set the width to the expression

    Thanks again for the help.
    czone



Back to Top