Im using Asp.Net and VB on Visual Studio 2010
Hi, i am using a System.Web.UI.WebControls.TextBox
with the wrap
property set to "true"
, my problem is that when it wraps a word, it moves the whole word to the next line, what i want to accomplish is for the textbox to wrap, but not move the whole word, just move to the new line when the text reaches the right side of the textbox.
Example, imagine a textbox 10 chars wide.
This is what happens:
0123456789
i am a
textbox
This is what i need:
0123456789
i am a tex
tbox
But if开发者_开发知识库 i set the wrapping to false, it just will keep expanding the width of the textbox on the same line.
I was thinking of setting the wrap to false, and use the onTextChanged event to check the length of the text and manually trigger the new line. is there any easier way to acomplish this?
Thanks a lot!
This is a web browser implementation issue rather than something that can be accomplished with ASP.NET.
The only way to control that, theoretically, would be to run JavaScript on the client end, but the route would require some heroics. You'd need to
- Have the JS calculate the length of the text entered
- Have the JS keep the original value of the text in a hidden INPUT field with some sort of line separator (i.e., "
i am a tex<LINEBREAK>tbox
"), that way you can discern real linebreaks from the user with the linebreaks that the JS puts in to chop off the end of the line - On submitting the form, don't use what's in the actual textbox but rather what's in the hidden INPUT field, with the
<LINEBREAK>
s replaced with empty strings.
But all of the above would require an enormous amount of effort, lots of testing across the various browsers, and breaks some of the built-in ASP.NET stuff (i.e., not using the contents of a textbox but rather a client side INPUT).
Replace all spaces with
and it will wrap as you required in your question.
However, the behavior fails if the user types any actual spaces into the text area.
I've not tested the return-value on post-back. You would need to test post-back results with and without edits included.
精彩评论