1

I have a little problem. I need to create a text editor in asp.net webforms. Therefore I managed to create only a div which is content editable. I like to ask, in this code, can I add some more functions, for example converting the selected text to upper case, lower case, add bullets, change fore and background color and so on. I have tried to add upper and lower case, but it needs to be in a text area, not in a div. For the bold, italic and underline functions to work, they need to be on a content editable div. Here is my code, thanks in advance!

<div id="txtPrev" contenteditable="true">Some example text</div>
<a href="#" class="embolden" onclick="emboldenFont()">B</a>
<a href="#" class="embolden" onclick="italicFont()">I</a>
<a href="#" class="embolden" onclick="underFont()">U</a>

<script>
    function emboldenFont() {
        document.execCommand('bold', false, null);
    }
    function italicFont() {
        document.execCommand('italic', false, null);
    }
    function underFont() {
        document.execCommand('underline', false, null);
    }
</script>
Lindsay
  • 95
  • 1
  • 9
  • 1
    Why would you want to develop this yourself? Use CKEditor or a similar editor – VDWWD Oct 25 '22 at 12:19
  • @VDWWD I have tried CKEditor, but I don't have all of the options that I need. Also I have tried freetextbox editor, but br tag is causing me problems. That is why I have asked this question, but thanks for the suggestion. – Lindsay Oct 25 '22 at 13:01
  • 1
    Gee, that is going to be a boatload of work. I would spend the using a pre built editor, and then modify from that point onwards. As noted, CKeditor is a great choice. Freetextbox is nice, and I been using for years the one that comes with the ajaxtoolkit. While adopting the whole ajaxtoolkit is quite a "big" add-in to adopt, it also has some other nice features such as a great ajaxfile-uploader, some really nice button extensions and more. And source code is available. So, lots of choices here. – Albert D. Kallal Oct 25 '22 at 17:10
  • I have tried again CKEditor, because I need it to be in update panel I have a huge problem. If I put a PostBack trigger on an ControlID of a button that I have to pass a text, the editor is gone. And if I use AsyncPostBackTrigger, the editor does not appear at all. @AlbertD.Kallal – Lindsay Oct 26 '22 at 09:27
  • Ok, so now you talking about a 100% different issue. The issue was never about some html editor, but that it not working for you. (and worse yet, if you spent the next 2 months writing your own editor, how do you know it would also not fail the same way??? - seems VERY much irresponsible to assume that writing your own editor would even address or fix these issues the right? But, wow, do I wish I had your software budgets!!! - gee, we can just build our own html editor - no problem!!! Nice working for some government/military with such deep pockets. Issue thus is fixing editor for post-backs – Albert D. Kallal Oct 26 '22 at 19:14
  • @AlbertD.Kallal I have solved my issue with freetextbox editor, you can check it here https://stackoverflow.com/questions/74056935/problem-with-br-tag-using-freetextbox-in-asp-net-webforms and thanks for your time, I am a student and still learning though I wish I worked for some government. – Lindsay Oct 27 '22 at 08:37

1 Answers1

0

The problem is solved with using an editor in my project.

Lindsay
  • 95
  • 1
  • 9