Specifying Width and Height properties as percentages

Discussion in 'ASP .Net' started by Nathan Sokalski, Jun 13, 2005.

  1. I am sure most of us have enough experience with HTML to know that most HTML
    elements allow you to specify the width and/or height attributes as
    percentages. However, I have noticed that when setting properties for an
    object on a webform (such as a TableCell) programmatically, the only way to
    do this is by using the Add method of the Attribute property as follows:

    webformobject.Attributes.Add("width", CStr(33) & "%")
    Even though this is not complicated to do, I would like to know why these
    objects do not have a direct property. Isn't one of the advantages of using
    ASP.NET supposed to be having it generate the code/attributes for us? If
    anyone knows a reason why the objects were designed this way, I would like
    to know. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jun 13, 2005
    #1
    1. Advertising

  2. Possibly because the developer think that it's more common to dynamically
    specifing the exact dimension than use percentage.

    Consider when you're adding a HtmlControl, the more common way to use the
    percentage is to specify the exact string:
    MyControl.Attribute.Add("width", "50%");

    If the user want to use exact dimension, he may need to do some calculation
    first, so making the properties integer will be more convinent(I doubt that
    if according to W3C decimal/double is legal value for width/height, they
    will be chosen instead).

    "Nathan Sokalski" <> ¼¶¼g©ó¶l¥ó·s»D:%...
    >I am sure most of us have enough experience with HTML to know that most
    >HTML elements allow you to specify the width and/or height attributes as
    >percentages. However, I have noticed that when setting properties for an
    >object on a webform (such as a TableCell) programmatically, the only way to
    >do this is by using the Add method of the Attribute property as follows:
    >
    > webformobject.Attributes.Add("width", CStr(33) & "%")
    > Even though this is not complicated to do, I would like to know why these
    > objects do not have a direct property. Isn't one of the advantages of
    > using ASP.NET supposed to be having it generate the code/attributes for
    > us? If anyone knows a reason why the objects were designed this way, I
    > would like to know. Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
     
    Lau Lei Cheong, Jun 13, 2005
    #2
    1. Advertising

  3. Greetings & Salutations,

    You can also (for server controls & a few others) use the Width property as
    well as the Unit class. Example:

    Label1.Width = Unit.Percentage(55.3)
    TableCell2.Height = Unit.Pixel(50)

    Gary K

    "Nathan Sokalski" wrote:

    > I am sure most of us have enough experience with HTML to know that most HTML
    > elements allow you to specify the width and/or height attributes as
    > percentages. However, I have noticed that when setting properties for an
    > object on a webform (such as a TableCell) programmatically, the only way to
    > do this is by using the Add method of the Attribute property as follows:
    >
    > webformobject.Attributes.Add("width", CStr(33) & "%")
    > Even though this is not complicated to do, I would like to know why these
    > objects do not have a direct property. Isn't one of the advantages of using
    > ASP.NET supposed to be having it generate the code/attributes for us? If
    > anyone knows a reason why the objects were designed this way, I would like
    > to know. Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
    >
     
    =?Utf-8?B?R2FyeSBL?=, Jun 15, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lois
    Replies:
    1
    Views:
    3,305
    Ryan Stewart
    Dec 27, 2004
  2. Bernd Meier
    Replies:
    6
    Views:
    529
    GTalbot
    Jan 14, 2008
  3. Nathan Sokalski

    Specifying Width and Height properties as percentages

    Nathan Sokalski, Jun 13, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    132
    Gary K
    Jun 15, 2005
  4. Nathan Sokalski

    Specifying Width and Height properties as percentages

    Nathan Sokalski, Jun 13, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    126
    Gary K
    Jun 15, 2005
  5. Catherine Lynn Smith

    createElement('img') and .width properties in percentages?

    Catherine Lynn Smith, Oct 6, 2003, in forum: Javascript
    Replies:
    2
    Views:
    179
    Lasse Reichstein Nielsen
    Oct 6, 2003
Loading...

Share This Page