views:

851

answers:

3

What is the exact pixel size of one column when I used the columns attribute to determine a width of an ASP.NET textbox control?

<asp:TextBox id="MyTextBox" runat="server" columns="10" />
+1  A: 

I always use:

style="width: 250px;"

That way you can set it exactly. Otherwise it's going to depend on the font-size of the textbox as well as the way the browser renders it.

Rows on the other hand is something I've always struggled with.

Ryan Smith
A: 

@Ryan Smith: I used your suggestion and modified it to make it scalable to the user montior settings.

style="width: 100%"
Michael Kniskern
+1  A: 

The Columns property is mapped to the size-attribute on the rendered input-tag.

If size is 10, then the browser is supposed to render the input field in a size that would make 10 characters fit and be visible in the input field. But that only really works for monospace fonts, since in many other fonts "III" will not have the same pixel length as "MMM".

So usually you are better of just using CSS-width as Ryan said.

Tom Jelen
I did use Ryan Smith suggestion....thank you for additional information.
Michael Kniskern