Multiline Textbox

J

John B

I have a Web User Control which contains amoung other things a multiline
textbox. We have found that long strings of data are being entered without
word breaks. The lack of breaks prevents the data from wrapping but rather
causes the control to expand horizontally. Is there anyway to have a
horizontal scrollbar to prevent the box from expanding?
 
K

Ken Cox [Microsoft MVP]

Hi John,

If you set the width of the textbox, you should get a horizontal scrollbar.

<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server" TextMode="MultiLine"
Height="112px" Width="248px" Wrap="False">I have a Web User Control which
contains amoung other things a multiline
textbox. We have found that long strings of data are being entered without
word breaks. The lack of breaks prevents the data from wrapping but rather
causes the control to expand horizontally. Is there anyway to have a
horizontal scrollbar to prevent the box from expanding?</asp:TextBox>
</form>
 
J

John B

We have difficulty in setting the width since this box is in a web control.
Depending on where the control is used the size of the control varies.
Typically it is dropped into a cell in a table and the cell width is set to a
percentage of the page width so that the page can be resized. We want the
control to occupy 100% of the cell but not grow beyond that point. Typically
the control is embedded several layers deep withing panels and tables within
a page. We have been trying in the code behind to step back through all the
parent containers until we find an absolute size the step forward applying
the relative sizes to that base finally arriving at an appropriate absolute
size for the textbox. To date we've not been successful.
 
R

Robert Koritnik

I know the problem. When there is a long line of text in the multiline
textbox it excedes its size if size is set to percentage. Absolute width
works fine. If you can't make it fixed size, there's something you should
try and I'll present two solutions that should do the trick. I think it
should because it would be client driven.

Ok. First what you could try. try putting multiline textbox into different
containers and see how it behaves regarding to that. But this probably won't
work.

A nasty dirty trick is to put a hidden field with this textbox and fill it
with the containing data. When the page loads on the client, you should only
be shure that textbox IS empty and put the content of the hidden input to
the textbox. I think this should work, but I admit it's dirty.

Another trick is to put a hiddent table on the page, that should have same
column widths as the table where that particular textbox resides. On the
page load event (client: onload) you should set it's width to the same size
as the hidden table column has.

One of these should work. I think the first solution with the hidden field
is less nasty as the second one...

Good luck and inform us about the result.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top