Collection in Widget Designer

Posted by Community Admin on 03-Aug-2018 13:06

Collection in Widget Designer

All Replies

Posted by Community Admin on 07-Mar-2011 00:00

I have been working over Sitefinity 4 since it has been launched. Few days back I ran into a situation where we needed to have collection (Dictionary, List etc) to be persistent in widget`s designer view, so that properties could be added, deleted existing options etc.

Here is a quick way to do that...

In the UserControl, we do like:

private Dictionary<string, string> _TestProperty = new Dictionary<string,string>();
        public string TestProperty
        
            get
            
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                if (_TestProperty.Count == 0)
                
                    _TestProperty.Add("val1", "abc");
                    _TestProperty.Add("val2", "xyz");
                
                return serializer.Serialize(_TestProperty);
            
            set
            
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                _TestProperty = (Dictionary<string, string>) serializer.Deserialize(value, typeof(Dictionary<string, string>));
            
        

And here is what we do in designer js file:
var data = this._propertyEditor.get_control();
var value = Sys.Serialization.JavaScriptSerializer.deserialize(data.TestProperty);

This thread is closed