locked
I have an htmleditorextender in a webform and want to only print the actual text, nothing else. How do I do that? RRS feed

  • Question

  • User-858993849 posted

    I have an htmleditorextender in a webform and want to only print the actual text, nothing else.  How do I do that?

    Tuesday, November 1, 2016 10:09 PM

All replies

  • User-1716253493 posted

    You can get text only from html string using regex.replace

    string textonly = Regex.Replace(htmlString, @"<(.|\n)*?>", "");

    Wednesday, November 2, 2016 5:57 AM
  • User1724605321 posted

    Hi JAYHAWKER,

    As @oned_gk said , you could use below RegularExpression:

    1. add namespace for System.Text.RegularExpression :

    using System.Text.RegularExpressions;

    2. add htmleditorextender :

        <form id="form1" runat="server">
            <asp:ScriptManager ID="ToolkitScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:TextBox runat="server"
                ID="txtBox1"
                TextMode="MultiLine"
                Columns="50"
                Rows="10"
                Text="Hello <b>world!</b>" />
    
            <asp:HtmlEditorExtender
                ID="htmlEditorExtender1" EnableSanitization="false"
                TargetControlID="txtBox1"
                runat="server">
            </asp:HtmlEditorExtender>
    
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </form>

    3. get Plain text:

            protected void Button1_Click(object sender, EventArgs e)
            {
                string strtext = "";
                strtext = Regex.Replace(txtBox1.Text, @"<(.|\n)*?>", string.Empty);
            }

    Best Regards,

    Nan Yu

    Wednesday, November 2, 2016 8:54 AM