views:

357

answers:

4

I have the following code

<table cellpadding="2" cellspacing="2">
  <tr>
    <td>Factory:</td>
    <td>
      <asp:TextBox ID="txtFactory" runat="server" Width="100%"></asp:TextBox>
    </td>
  </tr>
</table>

My problem is that sometimes the factory textbox can hold a fairly long description of 100 or more characters, and when this happens my textbox widens beyond the edge of the screen, which then causes a horizontal scrollbar to appear at the bottom of my browser, and I really don't want that. What I want is to have my TextBox extend to the width that the browser window is at, and to also be able to resize when the user resizes their browser window.

+1  A: 

Jagd,

Check the Wrap and MaxLength properties.

W3Schools has some great information on WebControls.

(http)://www.w3schools.(com)/aspnet/control_textbox.(asp)
---I can't post links yet, sorry---

Good Luck,

-Robert

Robert Greiner
+1  A: 

If you are not opposed to using javascript, jQuery has a very simple solution to this problem. You can use it to initially set the size of the textbox, and to attach a resize event handler to the body tag. In the event handler, simply have the textbox match its width to that of the body.

Ender
I flagrantly use javascript, but I've yet to begin using jQuery. S'pose I should start though. ;)
Jagd
+1  A: 

Check your HTML with FF using the Firebug and see what is widening your main container.

If your text its too long and has no spaces, the browser doesn't know where to place a line break, this behavior can be modified with the WRAP attribute in the TD or TextBox (which is rendered as a SPAN once in the browser).

Romias
+1  A: 

Where is your label for the form element? Why are you using tables for layout? Why are you specifying a width for the textarea in the HTML rather than in your CSS file?

Please do things properly!

Matthew James Taylor
Please, spare me the neurosism. I'm not asking for a table vs. div argument here. There are still times when one has to use a table tag.
Jagd