Search code examples
c#tinymcedetailsviewhtml-encode

how to html decode in a details view?


<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="SqlDataSource1" AutoGenerateRows="False"
DataKeyNames="ID" DefaultMode="Insert" >

...

<asp:TextBox ID="ShortExcerptTextBox" runat="server"
Text='<%#Bind("ShortExcerpt") %>' class="mceEditor"
TextMode="MultiLine"></asp:TextBox>

this is the code i have.

the problem is that i need to somehow HttpUtility.HtmlDecode it there in the #Bind("ShortExcerpt") somehow, but don't know how.

the original issue is that tinyMCE (rich text editor) encodes the text by itself but does not decode it on read. a long story :P

so please just, someone, explain, how to HttpUtility.HtmlDecode the text that gets read into #Bind("ShortExcerpt") please?

thnx


Solution

  • I don't think that you can use HtmlDecode with Bind.

    So either try to HtmlDecode the TextBox in codebehind:

    <asp:TextBox ID="ShortExcerptTextBox" runat="server"
        Text='<%# Eval("ShortExcerpt") %>' 
        OnDataBinding="ShortExcerptTextBox_DataBinding" class="mceEditor"
        TextMode="MultiLine">
    </asp:TextBox>
    
    
    protected void ShortExcerptTextBox_DataBinding(object sender, EventArgs e)
    {
        var txt = (TextBox)sender;
        txt.Text = HttpUtility.HtmlDecode(txt.Text);
    }
    

    or try to use Eval instead(if that is acceptable):

    <asp:TextBox ID="ShortExcerptTextBox" runat="server"
        Text='<%# HttpContext.Current.Server.HtmlDecode((string)Eval("ShortExcerpt")) %>' 
        class="mceEditor"
        TextMode="MultiLine">
    </asp:TextBox>
    

    Both not tested yet.