Question

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" /> 
Was it helpful?

Solution

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.

OTHER TIPS

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.

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

style="width: 100%"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top