Automatic line break in asp.net textbox control
I have a scenario in my application, by saving a text of length 20000 chars without line break in between.When i retrieve the s开发者_开发知识库ame to an asp.net textbox control my UI is stretching to the length of these 2000 chars in a single line . I have to wrap the text automatically inside text box. Can any one help to solve this issue ?
Thanks in advance. Pradeep
In my case, setting properties correctly on textbox didn't work. After searching through the web and not finding anything, I looked at the html source generated for the page. Turned out that one of the parent controls was emitting a 'white-space:nowrap' which got inherited by the textbox control. Added
style="white-space:normal"
to the textbox and voila that started making the wrap work.
Posting in case someone else runs into this.
You need to set the columns
property of the textbox to the maximum width you want.
There is also a width
property that will also set the width to a specific pixel size.
In either case, you need to specify that the text in the textbox should wrap by setting the wrap
property to true
.
<asp:TextBox ID="txt" columns="20" wrap="true" runat="server" />
精彩评论