user1721064
user1721064

Reputation: 21

.net c# asp.net make part of Textbox text bold

I have a .NET C#/Aspx web application in which users fill in fields and the resulting form is emailed out. I have a requirement to allow users to highlight text and then make that text either bold or coloured or both.

I have done a bit of searching on the net and found that javascript might be the best option. However, when the script inserts the html tags - it doesn't render within the textbox.I know this is a limitation of the asp.net textbox but is there anyway around this?

<script type="text/javascript"> 

function formatText(tag) {
    var selectedText = document.selection.createRange().text;

    if (selectedText != "") {
        var newText = "<" + tag + ">" + selectedText + "</" + tag + ">";
        document.selection.createRange().text = newText;
    }
} 

Upvotes: 2

Views: 2116

Answers (3)

G . R
G . R

Reputation: 541

Cannot be done in a Textbox.Go for any RichTextEditor. (CKEDITOR or CLEEDITOR)

Upvotes: 0

Erwin
Erwin

Reputation: 4817

Instead reinventing the wheel, take a look at a rich text editor, like for example TinyMCE you can strip it down, so the user only have the options like bold or italic.

More info how to create a simple example can be found here:

Create a very simple TinyMCE wysiwyg Editor

Upvotes: 3

System Down
System Down

Reputation: 6260

You'll need a rich text editor like ckeditor.

Upvotes: 7

Related Questions