Asp.Net文本框,如何换行拆分单词而不是移动到下一行
我在 Visual Studio 2010 上使用 Asp.Net 和 VB
您好,我正在使用 System.Web.UI.WebControls.TextBox
,并将 wrap
属性设置为 ” true”
,我的问题是,当它换行时,它将整个单词移动到下一行,我想要完成的是让文本框换行,但不移动整个单词,只是移动到当文本到达右侧时换行文本框的一侧。
例如,想象一个 10 个字符宽的文本框。
这就是发生的情况:
0123456789
i am a
textbox
这就是我需要的:
0123456789
i am a tex
tbox
但是如果我将换行设置为 false,它只会继续扩展同一行上文本框的宽度。
我正在考虑将换行设置为 false,并使用 onTextChanged 事件检查文本的长度并手动触发新行。有没有更简单的方法来完成这个?
多谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个 Web 浏览器实现问题,而不是可以使用 ASP.NET 来完成的问题。
从理论上讲,控制这一点的唯一方法是在客户端运行 JavaScript,但该方法需要一些英雄才能。您需要
i am a tex”)。 tbox
"),这样你就可以通过 JS 放入的换行符来辨别用户的真正换行符,以截断行尾
替换为空字符串。但上述所有内容都需要付出巨大的努力,在各种浏览器上进行大量测试,并且会破坏一些内置的 ASP.NET 内容(即不使用文本框的内容,而是使用客户端输入) 。
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
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<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.