Specifying Width and Height properties as percentages

N

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.
 
L

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).
 
G

Guest

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
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top