Home All Groups Group Topic Archive Search About

Specifying Width and Height properties as percentages

Author
13 Jun 2005 4:17 AM
Nathan Sokalski
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
njsokal***@hotmail.com
http://www.nathansokalski.com/

Author
13 Jun 2005 6:08 AM
Lau Lei Cheong
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).

Show quoteHide quote
"Nathan Sokalski" <njsokal***@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:%239l9K78bFHA.3***@TK2MSFTNGP12.phx.gbl...
>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
> njsokal***@hotmail.com
> http://www.nathansokalski.com/
>
>
Author
15 Jun 2005 3:36 AM
Gary K
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

Show quoteHide quote
"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
> njsokal***@hotmail.com
> http://www.nathansokalski.com/
>
>
>