1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Setting Complex Value back in the ControlDesigner

Setting Complex Value back in the ControlDesigner

2 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    26 Apr 2010
    Link to this post
    I've got a RadTreeView in my designer, and I can save the checked nodes out to a string fine, but I'm having a hard time loading them BACK in...what's the trick to this?

    protected override void InitializeControls(System.Web.UI.Control viewContainer) {
        if (((FileDownLoadBase)DesignedControl).SelectedFiles.Contains("|")) {
            List<string> itemIDs = ((FileDownLoadBase)DesignedControl).SelectedFiles.Split('|').Where( x=> !String.IsNullOrEmpty(x)).ToList();
     
            foreach (string id in itemIDs) {
                foreach (RadTreeNode node in DocumentsTree.Nodes) {
                    if (node.ID.ToLower() == id.ToLower())
                        node.Checked = true;
                }
            }
        }
    }

    I assume this will work...if my TreeView has Nodes :)

    I tried calling DataBind() on the DocumentsTree before this loop, but still no nodes...

    I'm setting the treeview data in Page_Init in the designer

    protected void Page_Init(object sender, EventArgs e) {
        if (!Page.IsPostBack) {
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    26 Apr 2010
    Link to this post
    Hello Steve,

    In your custom control you should have a ViewState property that will be used to set the value of the selected nodes.

    public string SelectedNodes
       {
           get
           {
               object obj = this.ViewState["SelectedNodes"];
               if (obj != null)
                   return (string)obj;
               return String.Empty;
     
           }
           set
           {
               this.ViewState["SelectedNodes"] = value;
           }
       }

    In the control designer you should override CreateChildControls () and set the selected nodes of the RadTreeView.

    protected override void CreateChildControls()
       {
           base.CreateChildControls();
     
           if (RadTreeView1 != null)
           {
               RadTreeView1.SelectedNodes = ((CustomControl)DesignedControl).SelectedNodes;
              
           }
       }


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
2 posts, 0 answered