This is a migrated thread and some comments may be shown as answers.

Appending SelectedValue when used on page with AjaxManager

8 Answers 219 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
LQKerry
Top achievements
Rank 1
LQKerry asked on 27 Sep 2013, 02:30 PM
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

8 Answers, 1 is accepted

Sort by
0
LQKerry
Top achievements
Rank 1
answered on 09 Oct 2013, 06:39 PM
Bump.... can anyone at least confirm that they can reproduce the issue?
1
Peter Filipov
Telerik team
answered on 14 Oct 2013, 12:03 PM
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.
0
Accepted
John
Top achievements
Rank 1
answered on 12 Dec 2013, 03:27 AM
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);
                }
            }
0
LQKerry
Top achievements
Rank 1
answered on 13 Dec 2013, 05:05 PM
John,

Thanks for posting the simple work around.
0
Anil
Top achievements
Rank 1
answered on 04 Apr 2016, 03:00 AM

I faced same issue when using DropDownTree....

Then I used radDropDownTree.EmbeddedTree.SelectedNode.Value

 

-Anil

 

0
juansimon
Top achievements
Rank 1
answered on 01 Jul 2016, 06:19 PM

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>

0
Nencho
Telerik team
answered on 06 Jul 2016, 10:39 AM
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.
0
Gregory
Top achievements
Rank 1
answered on 15 Jun 2017, 04:31 PM

If anyone is still experiencing this issue, John's code is helpful, with one small tweak necessary.  The line with the Substring needs to get the most recent value chosen, not the first one as it does now.  Each time a postback happens after selecting another choice, SelectedValue will have two items in it, the previous choice first and the current choice after the comma.  The selected value needs to be the current choice, so that line should read: 

rdtSectionId.SelectedValue = rdtSectionId.SelectedValue.Substring(pos + 1); 

Tags
DropDownTree
Asked by
LQKerry
Top achievements
Rank 1
Answers by
LQKerry
Top achievements
Rank 1
Peter Filipov
Telerik team
John
Top achievements
Rank 1
Anil
Top achievements
Rank 1
juansimon
Top achievements
Rank 1
Nencho
Telerik team
Gregory
Top achievements
Rank 1
Share this question
or