treeview with multiple nodetemplates and accessing controls after postbacks

3 posts, 0 answers
  1. Felipe
    Felipe avatar
    33 posts
    Member since:
    Dec 2010

    Posted 20 Apr 2011 Link to this post


    Hello,

    I seem to be having a problem with a radtreeview scenario and it is kind of putting my project to a halt right now.

    I have a radtreeview with AppendDataBoundItems="true".  in the markup I include one node by default - with a node template.

    i also bind the treeview with several more nodes (which are appended) and have a DIFFERENT NodeTemplate.

    I need to access the controls in the first node from code-behind, so in my page_load event I find the control and assign it to a protected page variable.

    This loads and works fine on page load.  Unfortanately, when I try to update the control via ajax - during the page_load it seems to have assigned the wrong template to the first node (it assigns the data-bound template instead).

    as a result, the control that I need does not exist, and there is an error, and the ajax request never completes.

    how can I get this to work across multiple updates?


    the markup for the treeview:
    <telerik:RadTreeView ID="RadTreeView1" runat="server"
                DataFieldID="ID" DataFieldParentID="ParentID"
                MultipleSelect="true"
                EnableDragAndDrop="true" OnClientDoubleClick="onNodeDoubleClick" OnClientNodeClicked="onNodeClick"
                EnableDragAndDropBetweenNodes="true" ShowLineImages="true"
                OnClientContextMenuItemClicking="onClientContextMenuItemClicking" OnClientNodeExpanded="onNodeExpanded"
                OnClientContextMenuShowing="onClientContextMenuShowing" Skin="dsSkin" EnableEmbeddedSkins="False" AppendDataBoundItems="true">
        <Nodes>
            <telerik:RadTreeNode Text="Document Date" Value="dateslider" >
                <NodeTemplate>Document Date</NodeTemplate>
                <Nodes>
                    <telerik:RadTreeNode Value="datesliderchild" >
                        <NodeTemplate>
                            <%-- Node Template with control which I need to access AFTER ajax requests --%>
                            <telerik:RadSlider runat="server" ID="radSliderDates" IsSelectionRangeEnabled="true" Width="250"
                                                    AutoPostBack="true" ShowDecreaseHandle="false" ShowIncreaseHandle="false"
                                                    OnClientValueChanging="onClientValueChanging"
                                                    OnClientSlideStart="onClientSlideStart"
                                                    OnClientSlideEnd="onClientSlideEnd"
                                                    OnClientSlide="onClientSlide" />
                        </NodeTemplate>
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeNode>
        </Nodes>
        <NodeTemplate>
            <%-- Global Node Template which I apply to data-bound items --%>
        </NodeTemplate>
    </telerik:RadTreeView>

    protected void Page_Load(object sender, EventArgs e)
    {
        #region Load Event Handlers
     
        //Find node I am looking for - then assign controls to protected page variables.
        //On postbacks/ajax requests, the node is found, but the FindControl method does not find anything because the node has the wrong template
        RadTreeNode node = RadTreeView1.FindNodeByValue("datesliderchild");
        radSliderDates = (RadSlider)node.FindControl("radSliderDates");
        lblSliderEndDate = (Label)node.FindControl("lblSliderEndDate");
        lblSliderStartDate = (Label)node.FindControl("lblSliderStartDate");
     
        radSliderDates.ValueChanged += new EventHandler(radSliderDates_ValueChanged);
     
        #endregion
     
        if (!IsPostBack)
        {
             
        }
    }


    ANY help on this is much appreciated!
  2. Felipe
    Felipe avatar
    33 posts
    Member since:
    Dec 2010

    Posted 20 Apr 2011 Link to this post

    UPDATE:

    OK, I found out a little bit more about the source of the problem....

    so part of the requirements that I have is that I am rebinding the treeview on certain postbacks/requests.

    when I rebind it, I am more or less adding the same nodes (with updated data) that were data-bound before....

    as a result, I am deleting the databound nodes from before (except for the first node, which is the special one), and then rebinding.

    you can see this here:

    private void BindTreeView()
    {
         
        while ((RadTreeView1.Nodes.Count > 1))
            RadTreeView1.Nodes.Remove(RadTreeView1.Nodes[1]);
     
        RadTreeView1.DataTextField = "DisplayText";
        RadTreeView1.DataSource = Results.Tables[2];
     
        RadTreeView1.DataBind();
     
    }

    If i remove the lines where I remove the nodes - everything works fine (minus the fact that I am now duplicating nodes in the treeview)


  3. Felipe
    Felipe avatar
    33 posts
    Member since:
    Dec 2010

    Posted 20 Apr 2011 Link to this post

    I believe I was able to work around the issue by putting the first node into an entirely separate radtreeview and styling them to look like they were part of the same control - not ideal for me but works well enough.
Back to Top