Try Now
More in this section

Forums / General Discussions / Collection in Widget Designer

Collection in Widget Designer

1 posts, 0 answered
  1. Saad
    Saad avatar
    98 posts
    10 Oct 2008
    07 Mar 2011
    Link to this post
    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
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    if (_TestProperty.Count == 0)
                        _TestProperty.Add("val1", "abc");
                        _TestProperty.Add("val2", "xyz");
                    return serializer.Serialize(_TestProperty);
                    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);
1 posts, 0 answered