Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Anders Hattestad
Oct 16, 2008
  13250
(1 votes)

Dynamic content and State attribute

I had a problem with the State attribute. This is the attribute that is saved inside the span [SPAN class=dynamiccontent contentEditable=false style="....." disabled hash="oqAE..zt1Y=" state="xxx"][/SPAN]

I tried to save some xml inside it, and the dynamic content render just wouldnt save. it seems like the attribute can contains html/xml tags.

The trick was to convert my string into Base64.

public string Value;
#region Value64
public string Value64
{
    get
    {
        if (Value == null)
            return null;
        return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes((string)Value));

    }
    set
    {
        if (value != null)
        {
            
            byte[] toDecodeByte = Convert.FromBase64String(value);

            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();

            int charCount = utf8Decode.GetCharCount(toDecodeByte, 0, toDecodeByte.Length);

            char[] decodedChar = new char[charCount];
            utf8Decode.GetChars(toDecodeByte, 0, toDecodeByte.Length, decodedChar, 0);
            string result = new String(decodedChar);
            Value = result;

        }
    }
}
#endregion
#region State (64)
public string State
{
    get
    {
            return Value64;
    }
    set
    {
        Value64 = value;
        
    }
}
#endregion
Oct 16, 2008

Comments

Sep 21, 2010 10:32 AM

Good post Anders. Because the state string is stored as part of the XHTML Property it cannot contain XML in raw form. In these cases we recommend Binary Serialization as you have used. Paul EPiServer Dev Team
/ Paul Smith

Sep 21, 2010 10:32 AM

Thx, but couldn't the function that retrives the State string convert it for us?
/ Anders Hattestad (hattestad@gazette.no)

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog