RadTreeView in RadComboBox causes full (non-AJAX) Postback

7 posts, 1 answers
  1. Jay
    Jay avatar
    89 posts
    Member since:
    Nov 2007

    Posted 29 Oct 2008 Link to this post

    I've embedded a RadTreeView in a RadComboBox much like the online example, except that I've added event handlers to the RadTreeView for the NodeClick event.  I've also wrapped all of this in an AJAX Panel to avoid causing a full page post-back.  But, it seems like the RadTreeView simply ignores this AJAX wrapper and causes a full page post-back anyway.

    I've included a code sample:
    <%@ Page Language="C#" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <script runat="server"
        protected void TreeView_SelectedIndexChanged( object sender, EventArgs e ) 
        { 
            RadTreeView rtv = (RadTreeView) sender; 
            RadComboBoxItem item = CB1.SelectedItem; 
            item.Text = rtv.SelectedNode.Text; 
            item.Value = rtv.SelectedValue; 
        } 
     
        protected void ComboBox_SelectedIndexChanged( object sender, EventArgs e ) 
        { 
            RadComboBox rcb = sender as RadComboBox; 
            LIT1.Text = rcb.SelectedItem.Text; 
        } 
    </script> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title></title
    </head> 
    <body> 
        <form id="form1" runat="server"
        <asp:ScriptManager ID="Mgr1" runat="server"></asp:ScriptManager> 
     
        <telerik:RadAjaxPanel ID="RAP1" runat="server" EnableAJAX="true"
            <telerik:RadComboBox ID="CB1" runat="server" AutoPostBack="true"
                <ItemTemplate> 
                    <telerik:RadTreeView ID="TV1" runat="server" OnNodeClick="TreeView_SelectedIndexChanged"
                        <Nodes> 
                            <telerik:RadTreeNode Text="Node 1" Value="1"></telerik:RadTreeNode> 
                            <telerik:RadTreeNode Text="Node 2 - Parent" Value="1"
                                <Nodes> 
                                    <telerik:RadTreeNode Text="Node 2.1" Value="2.1"></telerik:RadTreeNode> 
                                    <telerik:RadTreeNode Text="Node 2.2" Value="2.2"></telerik:RadTreeNode> 
                                </Nodes> 
                            </telerik:RadTreeNode> 
                            <telerik:RadTreeNode Text="Node 3" Value="3"></telerik:RadTreeNode> 
                        </Nodes> 
                    </telerik:RadTreeView> 
                </ItemTemplate> 
                <Items> 
                    <telerik:RadComboBoxItem Text="None" Value="" /> 
                </Items> 
            </telerik:RadComboBox> 
        </telerik:RadAjaxPanel> 
         
        <telerik:RadAjaxPanel ID="RAP2" runat="server" EnableAJAX="true"
            <telerik:RadComboBox ID="CB2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ComboBox_SelectedIndexChanged"
                <Items> 
                    <telerik:RadComboBoxItem Text="Item 1" Value="1" /> 
                    <telerik:RadComboBoxItem Text="Item 2" Value="2" /> 
                    <telerik:RadComboBoxItem Text="Item 3" Value="3" /> 
                </Items> 
            </telerik:RadComboBox> 
            <asp:Literal ID="LIT1" runat="server">Item Value</asp:Literal> 
        </telerik:RadAjaxPanel> 
        </form> 
    </body> 
    </html> 
     

    I included the second RadComboBox just to show that the AJAX panel works for simpler controls.


  2. Jay
    Jay avatar
    89 posts
    Member since:
    Nov 2007

    Posted 29 Oct 2008 Link to this post

    I just found an entry on this in your troubleshooting pages and will attempt to include the "attachDropDown" method to see if I can fix this.
  3. Jay
    Jay avatar
    89 posts
    Member since:
    Nov 2007

    Posted 29 Oct 2008 Link to this post

    I used the attachDropDown method, which worked for the particular sample by adding a bit of client-side script.  But, were I to use this method in a custom control to embed within a page potentially multiple times, the
    $find( "<%= CB1.ClientID %>" ) 
    call would not work (consistently).  And, as I found, adding the attachDropDown call on the RadComboBox's client load event doesn't work at all, either.
  4. Answer
    Rosi
    Admin
    Rosi avatar
    2529 posts

    Posted 30 Oct 2008 Link to this post

    Hi Jay,

    I suggest you call the attachDropDown() method of RadComboBox in the event handler of OnClientNodeClicking of RadTreeView.

    Hope this helps.

    Kind regards,
    Rosi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Jay
    Jay avatar
    89 posts
    Member since:
    Nov 2007

    Posted 31 Oct 2008 Link to this post

    The attachDropDown call does work in the OnClientNodeClicking handler, but if I include these control in a custom control, which I replicate multiple times in a page, the $find function ceases to produce predictable results, since the page has mutiple script blocks with functions having the same name, so we won't know which version of the function the Javascript engine will call.  So, the attachDropDown does solve the problem in simple single-use situations, but we can't use it this way reliably in more complex applications.
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 03 Nov 2008 Link to this post

    Hi Jay,

    I believe that this KB article will help you in your complex scenario:
    (ID#921) Using dynamic/unique names for JavaScript functions

    All the best,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Jay
    Jay avatar
    89 posts
    Member since:
    Nov 2007

    Posted 03 Nov 2008 Link to this post

    Thanks for the link!
Back to Top