Actual pixel size of columns attribute for asp.net textbox

What is the exact pixel size of one column when I used the columns attribute to define the width of the ASP.NET text box control?

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

      

+1


source to share


3 answers


I always use:

style="width: 250px;"

      



This way you can set it exactly. Otherwise, it will depend on the font size of the text box as well as how the browser renders it.

On the other hand, strings are something I've always struggled with.

+1


source


The Columns property maps to the size attribute on the rendered input tag.

If the size is 10, the browser should render the input field at a size that is 10 characters long and visible in the input field. But this really only works for monospaced fonts, since in many other fonts "III" will not have the same pixel length as "MMM".



Generally, you're better off just using CSS width as Ryan said.

+5


source


@Ryan Smith: I used your suggestion and modified it to be scalable for custom montior settings.

style="width: 100%"

      

-1


source







All Articles