问题描述
我有一个标准的asp:文本框是可编辑的,我希望能够选择文本的一部分,点击一个按钮,然后封装HTML标记选定的文本
I have a standard asp:textbox which is editable and I want to be able to select a portion of text, click a button, and then encapsulate the selected text with html tags.
例如文本框有这样的文字:
For example the textbox has this text:
敏捷的棕色狐狸跳过懒狗。
The quick brown fox jumps over the lazy dog.
如果我选择敏捷的棕色狐狸,然后点击一个按钮,我想要的文字变成< I>在快速的棕色狐狸< / I>
If I select "The quick brown fox" and click a button I want the text to become <i>The quick brown fox</i>
如何检测所选文本?随着的WinForms,你可以使用RichTextBox的,但在标准asp.net控件没有这样的事情。而且还必须是一个asp:texbox控
How to detect the selected text? With winforms you can use richtextbox but no such thing in standard asp.net controls. And it also MUST be an asp:texbox control.
推荐答案
我很少推荐这个,因为控制有点笨重,但你可以使用的这一点。只需按照网站上的说明来安装该工具包,并在项目中包含该DLL。
I rarely recommend this, because the controls are kind of clunky, but you could use the ASP.NET AJAX Control Toolkit for this. Just follow the instructions on the website to install the toolkit, and include the DLL in your project.
该工具包具有您可以应用到正常值℃的扩展; ASP:文本框&GT;
名为 HTMLEditorExtender
。见的功能链接页面上的样本。基本上,所有你所要做的就是在现有的文本框
控制点的 HTMLEditorExtender
标记。
The toolkit has an extender that you can apply to a normal <asp:TextBox>
called HTMLEditorExtender
. See the samples on the linked page for the functionality. Basically, all you have to do is point the HTMLEditorExtender
markup at an existing TextBox
control.
下面是从页面上的示例的简化版本:
Here's a simplified version from the sample on that page:
<ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1"
TargetControlID="yourTextBoxID" DisplaySourceTab="true"
runat="server"/>
<Toolbar>
<ajaxToolkit:Bold />
<ajaxToolkit:Italic />
<ajaxToolkit:Underline />
<ajaxToolkit:StrikeThrough />
<ajaxToolkit:RemoveFormat />
<ajaxToolkit:BackgroundColorSelector />
<ajaxToolkit:ForeColorSelector />
<ajaxToolkit:FontNameSelector />
<ajaxToolkit:FontSizeSelector />
</Toolbar>
</ajaxToolkit:HtmlEditorExtender>
请注意,你需要在的TargetControlID =yourTextBoxID
设置yourTextBoxID到你想要的扩展应用到TextBox控件的ID。
Note that you need to set "yourTextBoxID" in TargetControlID="yourTextBoxID"
to the ID of the TextBox control you want the extender to apply to.
这篇关于asp.net文本框的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!