Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi EB,

I have an asp.net page, where every control has width in '%' form.
There is one text box, which need to be single line text; if an user provide some lengthy data, upon postback, this data will widens textbox control. At coding time its width is fixed in '%' form in aspx page.

Please let me know how to keep width of textbox and form fixed?


Regards,
Nilesh
Posted

Since the control width is in %, it increases the width. You need to use conditional expression to set the width. Where till a certain length like 300px use % and after that always a fixed width of 300px.

UPDATE:
Here is it![^]
 
Share this answer
 
v2
Use the style parameter with a width property within the tag. Here is an example of one from within this very page;

<textarea class="RateComment" rows="5" cols="60" style="width:285px;float:right">

UPDATE: He is using a textbox(not a textarea) and has % as width. Fixing it to 285 would always have this width. It looks like he needs to avoid widening of the page based on long text entered into the textbox whose width is set in % such that it occupies all the available space while loading. (Issue crops up when length of text inside the texbox drives the width and not the page avaialble space)
[Update2: I know, the intent was to show the availability of the style element, nothing else. Cheers, Davie.]
 
Share this answer
 
v4
You may use max-width property
Write something like this in your CSS file:
CSS
.textbox1
{
  max-width: 300px;
  width: 100% !important
}


where, textbox1 is the id of the textbox.
you can replace 100% with whatever you have specified in your code.

It works on IE6+ and Mozilla 3.5+ browsers. Have not checked for previous versions.
Check it out and let me know if this it what you wanted. :thumbsup:

Cheers!
Ankur
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900