[CLOSED] [1.0] ComboBox with HTML encoded data

  1. #1

    [CLOSED] [1.0] ComboBox with HTML encoded data

    In the example below I've got two ComboBoxes, each of them linking to a Store - one of which contains some un-encoded HTML characters, and the other contains encoded HTML characters.

    In the "Encoded" ComboBox, the drop-down list displays the values correctly because the HTML is encoded, however when a value is selected the encoded characters are inserted in to the ComboBox's text field.

    In the "Decoded" ComboBox, the drop-down list displays the values incorrectly (it renders the HTML tags) because the HTML hasn't been decoded, however when a value is selected the correct formatted text is inserted in to the ComboBox's text field.

    Is there a simple solution to allow the "Encoded" ComboBox to work as intended (i.e. upon selection of a value, display the correctly formatted text)? I have a lot of ComboBoxes, each of which displays data from the database that has been HTML encoded, so if there is a global change I can make to allow this to work correctly, it would be appreciated.

    I know most users aren't likely to add records with HTML characters, but we need to be sure we're not opening our application up to attack by allowing HTML to be rendered from the database.

    Many thanks,

    Dan

    <%@ Page Language="C#" %>
    <%@ OutputCache Location="None" VaryByParam="None"%>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            strEncoded.DataSource = new object[]
            {
                new object [] { 1, "&amp;lt;br&amp;gt;Test&amp;lt;/br&amp;gt;" },
                new object [] { 2, "&amp;lt;b&amp;gt;Test&amp;lt;/b&amp;gt;" }
            };
            strEncoded.DataBind();
            
            strDecoded.DataSource = new object[] 
            {
                new object [] { 1, "<br>Test</br>" },
                new object [] { 2, "Test" }
            };
            strDecoded.DataBind();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="rsmMain" runat="server">
            </ext:ResourceManager>
                    
            <ext:Store ID="strEncoded" runat="server">
                <Reader>
                    <ext:ArrayReader IDProperty="DataID">
                        <Fields>
                            <ext:RecordField Name="DataID" Type="Int"></ext:RecordField>
                            <ext:RecordField Name="DataName" Type="String"></ext:RecordField>
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
            
            <ext:Store ID="strDecoded" runat="server">
                <Reader>
                    <ext:ArrayReader IDProperty="DataID">
                        <Fields>
                            <ext:RecordField Name="DataID" Type="Int"></ext:RecordField>
                            <ext:RecordField Name="DataName" Type="String"></ext:RecordField>
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
                    
            <ext:FormPanel runat="server" Width="600">
                <Items>
                    <ext:ComboBox Width="400" runat="server" FieldLabel="Encoded" StoreID="strEncoded" ValueField="DataID" DisplayField="DataName"></ext:ComboBox>
                    <ext:ComboBox Width="400" runat="server" FieldLabel="Decoded" StoreID="strDecoded" ValueField="DataID" DisplayField="DataName"></ext:ComboBox>
                </Items>
            </ext:FormPanel>
        </form>
    </body>
    </html>
  2. #2

    RE: [CLOSED] [1.0] ComboBox with HTML encoded data

    Hi,

    I don't know simple global solution. You should use Template to solve that problem. Please see the following sample which shows how to fix the issue for both combos

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ OutputCache Location="None" VaryByParam="None"%>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            strEncoded.DataSource = new object[]
            {
                new object [] { 1, "&amp;lt;br&amp;gt;Test&amp;lt;/br&amp;gt;" },
                new object [] { 2, "&amp;lt;b&amp;gt;Test&amp;lt;/b&amp;gt;" }
            };
            strEncoded.DataBind();
            
            strDecoded.DataSource = new object[] 
            {
                new object [] { 1, "<br>Test</br>" },
                new object [] { 2, "Test" }
            };
            strDecoded.DataBind();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="rsmMain" runat="server">
            </ext:ResourceManager>
                    
            <ext:Store ID="strEncoded" runat="server">
                <Reader>
                    <ext:ArrayReader IDProperty="DataID">
                        <Fields>
                            <ext:RecordField Name="DataID" Type="Int"></ext:RecordField>
                            <ext:RecordField Name="DataName" Type="String"></ext:RecordField>
                            <ext:RecordField Name="DataNameDecoded" Type="String">
                                <Convert Handler="return Ext.util.Format.htmlDecode(record[1]);" />
                            </ext:RecordField>
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
            
            <ext:Store ID="strDecoded" runat="server">
                <Reader>
                    <ext:ArrayReader IDProperty="DataID">
                        <Fields>
                            <ext:RecordField Name="DataID" Type="Int"></ext:RecordField>
                            <ext:RecordField Name="DataName" Type="String"></ext:RecordField>
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
                    
            <ext:FormPanel ID="FormPanel1" runat="server" Width="600">
                <Items>
                    <ext:ComboBox ID="ComboBox1" Width="400" runat="server" FieldLabel="Encoded" StoreID="strEncoded" ValueField="DataID" DisplayField="DataNameDecoded">
                        <Template>
                            <tpl for=".">
                                <div class="x-combo-list-item">
                                     {DataName}
                                
    
                            </tpl>
                        </Template>
                    </ext:ComboBox>
                    
                    <ext:ComboBox ID="ComboBox2" Width="400" runat="server" FieldLabel="Decoded" StoreID="strDecoded" ValueField="DataID" DisplayField="DataName">
                        <Template>
                            <tpl for=".">
                                <div class="x-combo-list-item">
                                     {DataName:htmlEncode}
                                
    
                            </tpl>
                        </Template>
                    </ext:ComboBox>
                </Items>
            </ext:FormPanel>
        </form>
    </body>
    </html>
  3. #3

    RE: [CLOSED] [1.0] ComboBox with HTML encoded data

    Hi,

    I run into the same problem and too have many comboboxes and obviously using the template is not the best solution.


    I can provide HTML encoded data on the server, but obviously the selection text box will show them as such. Would it be possible to add some property to the selection text box that would automatically HTML decode the value set?


    Regards,
    Tadeusz

Similar Threads

  1. Exporting Grid Data for Excel, CSV, XML, HTML, PDF [EXAMPLE Codes]
    By fatihunal in forum Examples and Extras
    Replies: 6
    Last Post: Oct 07, 2016, 1:50 PM
  2. [CLOSED] HtmlEditor text is rendered HTML encoded
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Feb 22, 2012, 3:04 PM
  3. [CLOSED] Note is always encoded
    By r_honey in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 23, 2011, 8:53 PM
  4. 0.82 encoded html getting decoded on store
    By [WP]joju in forum 1.x Help
    Replies: 15
    Last Post: Dec 23, 2009, 6:40 AM
  5. HtmlEditor sometimes text is displayed encoded
    By alexp in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 24, 2009, 2:48 PM

Posting Permissions