Search code examples
asp.netrichtextboxfreetextbox

Rich TextBox accepting Script tags also


I have a aspx form where we have used freetextbox as my rich text editor to make entries.

but I am able to enter <script></script> in this reach tags.

how can i validate on client side that it should not accept any scripting which ever it is included in javascript library.

EDIT:

how can i validate it for not allowing script tags into it? how can we validate it for mandatory field? How can i manage more than one textareas on my page. but i want only one to be as rich editor and not all???

I had tried some code but it did not helped me for proper validation. below is the snippet. SCRITPT

<script>
    $(document).ready(function () {

        var $btn = $("#<%=btnSubmit.ClientID %>");
        var $txtEditor = $("#<%=txtEditor.ClientID %>");

        $btn.click(function () {
            alert($txtEditor.html()); 
            return false;
        })

    });

</script>

HTML

<div>
            <asp:TextBox id="txtEditor" runat="server" TextMode="MultiLine"></asp:TextBox>
        </div>
        <div>
        <asp:Button id="btnSubmit" runat="server" Text="Save" />

        </div>

Solution

  • If you do need support HTML in your text, then you probably should integrate some WYSIWYG editor (TinyMCE for example).

    If you don't need html there, then just html encode all user input.