Appending SelectedValue when used on page with AjaxManager

8 posts, 1 answers
  1. LQKerry
    LQKerry avatar
    4 posts
    Member since:
    May 2013

    Posted 27 Sep 2013 Link to this post

    I believe I have identified a bug with the RadDropDownTree control when it is used on a page with the AjaxManager but is not one of the updated controls of an Ajax postback. I have noticed and captured where the RadDropDownTree only has one selected value, but when checking the RadDropDownTree's SelectedValue it often has the selected value listed multiples times after the Ajax postback. Below is the example code I put together and steps I am able to reproduce the issue.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadDropDownTreeTest.aspx.cs" Inherits="ALPS.Net.Development.RadDropDownTreeTest" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadDropDownList1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadDropDownList2" />
                            <telerik:AjaxUpdatedControl ControlID="SelectedValue" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel>
            <div>
                <telerik:RadDropDownList ID="RadDropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadDropDownList1_SelectedIndexChanged">
                    <Items>
                        <telerik:DropDownListItem Value="alpha" Text="Alpha" Selected="true" />
                        <telerik:DropDownListItem Value="num" Text="Numeric" />
                    </Items>
                </telerik:RadDropDownList>  
            </div>
            <div>
                <telerik:RadDropDownList ID="RadDropDownList2" runat="server"></telerik:RadDropDownList>
            </div>
            <div>
                <telerik:RadDropDownTree ID="RadDropDownTree1" runat="server" DataFieldParentID="ParentID" DataFieldID="ID" DataTextField="Text" DataValueField="Value">
                </telerik:RadDropDownTree>
            </div>
            <div>
                <asp:Label ID="SelectedValue" runat="server" />
            </div>
        </form>
    </body>
    </html>

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    namespace ALPS.Net.Development
    {
        public partial class RadDropDownTreeTest : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                RadDropDownTree1.DataSource = GetData();
                RadDropDownTree1.NodeDataBound += RadDropDownTree1_NodeDataBound;
     
                if (!IsPostBack)
                {
                    BuildAlphaList();
                    RadDropDownTree1.DataBind();
                }
     
                SelectedValue.Text = RadDropDownTree1.SelectedValue;
            }
     
            void RadDropDownTree1_NodeDataBound(object sender, Telerik.Web.UI.DropDownTreeNodeDataBoundEventArguments e)
            {
                if (e.DropDownTreeNode.Text == "Text2 ")
                    e.DropDownTreeNode.CreateEntry();
            }
     
            public DataTable GetData()
            {
                DataTable table = new DataTable();
                table.Columns.Add("ID");
                table.Columns.Add("ParentID");
                table.Columns.Add("Value");
                table.Columns.Add("Text");
     
     
                table.Rows.Add(new String[] { "1", null, "customValue1", "Text1 " });
                table.Rows.Add(new String[] { "2", "1", "customValue2", "Text2 " });
                table.Rows.Add(new String[] { "3", "2", "customValue3", "Text3 " });
                table.Rows.Add(new String[] { "4", "3", "customValue4", "Text4 " });
                table.Rows.Add(new String[] { "5", "3", "customValue5", "Text5 " });
                table.Rows.Add(new String[] { "6", "5", "customValue2", "Text6 " });
                table.Rows.Add(new String[] { "7", "6", "customValue2", "Text7 " });
                table.Rows.Add(new String[] { "8", "7", "customValue2", "Text8 " });
                table.Rows.Add(new String[] { "9", "1", "customValue9", "Text9 " });
                table.Rows.Add(new String[] { "10", "1", "customValue10", "Text10 " });
     
                return table;
            }
     
            public void BuildAlphaList()
            {
                RadDropDownList2.Items.Clear();
     
                RadDropDownList2.Items.Add(new DropDownListItem { Value="A", Text="A" });
                RadDropDownList2.Items.Add(new DropDownListItem { Value = "B", Text = "B" });
                RadDropDownList2.Items.Add(new DropDownListItem { Value = "C", Text = "C" });
            }
     
            public void BuildNumList()
            {
                RadDropDownList2.Items.Clear();
     
                RadDropDownList2.Items.Add(new DropDownListItem { Value = "1", Text = "1" });
                RadDropDownList2.Items.Add(new DropDownListItem { Value = "2", Text = "2" });
                RadDropDownList2.Items.Add(new DropDownListItem { Value = "3", Text = "3" });
            }
     
            protected void RadDropDownList1_SelectedIndexChanged(object sender, DropDownListEventArgs e)
            {
                if (e.Value == "alpha")
                    BuildAlphaList();
                else
                    BuildNumList();
            }
        }
    }

    STEPS:
    1. Load the page.
    2. From the RadDropDownTree control select the top most node "Text1"
    3. From the first RadDropDownList select Numeric and notice the value of the label ("customValue1")
    4. From the first RadDropdownList select Alpha and again notice the value of the label ("customValue1,customValue1")
    5. From the first RadDropDownList select Numeric again and again view the label ("customValue1,customValue1,customValue1")

    If you were to add the RadDropDownTree as an updated control in AjaxManager, reload the page, and try the steps again the selected value works as expected having only the single selected value.

    If you were to comment out the AjaxManager, reload the page, and try the steps again the Selected value operates as expected only having the single SelectedValue.

    Bug or is there some setting I am missing? Thanks!

    Kerry
  2. LQKerry
    LQKerry avatar
    4 posts
    Member since:
    May 2013

    Posted 09 Oct 2013 Link to this post

    Bump.... can anyone at least confirm that they can reproduce the issue?
  3. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 14 Oct 2013 Link to this post

    Hi Kerry,

    In order to work properly the control should be updated by the RadAjaxManager, because the client state of the control is not reset and on every postback a new entry is created.

    Regards,
    Peter Filipov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  4. Answer
    John
    John avatar
    31 posts
    Member since:
    May 2011

    Posted 11 Dec 2013 Link to this post

    Just came across this "feature" myself.

    My workaround was to check for this on PostBack in PageLoad. Fortunately everywhere I used this control it was wrapped in a user control to workaround various other "features" so was simple to implement.

    NB. This only suits for single selection.

    Although I wasn't happy with the old RadTreeView inside RadComboBox it was a lot more reliable than this new control. I wish I hadn't updated!
    protected void Page_Load(object sender, EventArgs e)
            {
                if (Page.IsPostBack)
                {
                    int pos = rdtSectionId.SelectedValue.IndexOf(",");
                    if (pos != -1)
                    {
                        rdtSectionId.SelectedValue = rdtSectionId.SelectedValue.Substring(0, pos);
                    }
                }
  5. LQKerry
    LQKerry avatar
    4 posts
    Member since:
    May 2013

    Posted 13 Dec 2013 Link to this post

    John,

    Thanks for posting the simple work around.
  6. Anil
    Anil avatar
    8 posts
    Member since:
    Jun 2013

    Posted 03 Apr 2016 Link to this post

    I faced same issue when using DropDownTree....

    Then I used radDropDownTree.EmbeddedTree.SelectedNode.Value

     

    -Anil

     

  7. juansimon
    juansimon avatar
    5 posts
    Member since:
    Feb 2011

    Posted 01 Jul 2016 in reply to Anil Link to this post

    It works!! thanks!!

    The CheckBoxes="None" option doesn't work. 

                             <telerik:RadDropDownTree runat="server" ID="cmbDueno" Width="700px"
                                        CheckBoxes="None"
                                        DefaultMessage="Seleccione"  
                                        DataValueField="CodJerarquia" DataFieldParentID="PadreJerarquia"
                                        DataFieldID="Codigo" DataTextField="Nombre"
                                        DataSourceID="ObjectDataSource16">
                                        <DropDownSettings Height="340px" CloseDropDownOnSelection="true"/>
                                    </telerik:RadDropDownTree>

  8. Nencho
    Admin
    Nencho avatar
    1560 posts

    Posted 06 Jul 2016 Link to this post

    Hello Juansimon,

    Could you please elaborate a bit more on what exactly is the problem that you are experiencing with the Checkboxes in the DropDownTree and particularly - "The CheckBoxes="None" option doesn't work. "?


    Regards,
    Nencho
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top