RadComboBox Losing Client Selections on PostBack

15 posts, 0 answers
  1. Josh
    Josh avatar
    16 posts
    Member since:
    Feb 2014

    Posted 06 Apr 2015 Link to this post

    I have a combination of RadDropDownLists and RadComboBox's on a page, the last RadComboBox is losing it's selection(s) on PostBack. All other RadDropDownLists and RadComboBox's keep their selections on PostBack. What do I need to do to ensure the selections are not lost. I have tried enabling ViewState and several other suggestions found online, but none resolve the issue. Please advise.

    ASPX:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="CobraStatusTemplate1.aspx.cs" Inherits="CobraStatus.aspx.CobraStatusTemplate1" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
     
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
        <br />
        <telerik:RadDropDownList ID="rdlProject" runat="server" DefaultMessage="Select Project"
            OnSelectedIndexChanged="rdlProject_SelectedIndexChanged" AutoPostBack="true" Skin="Office2010Black" Enabled="true">
        </telerik:RadDropDownList>
     
        <telerik:RadDropDownList ID="rdlAnalyst" runat="server" DefaultMessage="Select Analyst"
            OnSelectedIndexChanged="rdlAnalyst_SelectedIndexChanged" AutoPostBack="true" Skin="Office2010Black" Enabled="false">
        </telerik:RadDropDownList>
     
        <telerik:RadComboBox ID="rcbControlAccount" runat="server" Text="Select Control Account" CheckBoxes="true"
            EnableCheckAllItemsCheckBox="true" OnSelectedIndexChanged="rcbControlAccount_SelectedIndexChanged" AutoPostBack="true" Skin="Office2010Black"
            Enabled="false">
        </telerik:RadComboBox>
     
        <telerik:RadComboBox ID="rcbEVT" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" AutoPostBack="true" Skin="Office2010Black"
            Enabled="false" OnSelectedIndexChanged="rcbEVT_SelectedIndexChanged">
        </telerik:RadComboBox>
     
        <br />
        <br />
     
        <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" GroupPanelPosition="Top" OnItemDataBound="RadGrid1_ItemDataBound"
            OnPreRender="RadGrid1_PreRender" OnBatchEditCommand="RadGrid1_BatchEditCommand" Width="100%" Skin="Office2010Black">
            <MasterTableView AutoGenerateColumns="False" EditMode="Batch" CommandItemDisplay="Top" Width="100%">
                <CommandItemSettings ShowAddNewRecordButton="False" ShowSaveChangesButton="True" ShowCancelChangesButton="True"></CommandItemSettings>
                <Columns>
                    <telerik:GridBoundColumn DataField="Project" HeaderText="Project" SortExpression="Project" UniqueName="Project"
                        FilterControlAltText="Filter Project column" ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Ca1" HeaderText="Control Account" SortExpression="Ca1" UniqueName="Ca1"
                        FilterControlAltText="Filter Ca1 column" ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Wp" HeaderText="Work Package" SortExpression="Wp" UniqueName="Wp" FilterControlAltText="Filter Wp column"
                        ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Descrip" HeaderText="Description" SortExpression="Descrip" UniqueName="Descrip"
                        FilterControlAltText="Filter Descrip column" ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Description" HeaderText="EV Technique" SortExpression="Pmt" UniqueName="Pmt"
                        FilterControlAltText="Filter Pmt column" ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="FullName" HeaderText="Analyst" SortExpression="C5" UniqueName="C5" FilterControlAltText="Filter C5 column"
                        ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="PcComp" HeaderText="% Complete" SortExpression="PcComp" UniqueName="PcComp" DataType="System.Decimal"
                        FilterControlAltText="Filter PcComp column" ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Ssd" HeaderText="Baseline Start Date" SortExpression="Ssd" UniqueName="Ssd" DataType="System.DateTime"
                        FilterControlAltText="Filter Ssd column" DataFormatString="{0:MM/dd/yyyy}" ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Sfd" HeaderText="Baseline Finish Date" SortExpression="Sfd" UniqueName="Sfd" DataType="System.DateTime"
                        FilterControlAltText="Filter Sfd column" DataFormatString="{0:MM/dd/yyyy}" ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridDateTimeColumn DataField="Asd" HeaderText="Actual Start Date" SortExpression="Asd" UniqueName="Asd" DataType="System.DateTime"
                        FilterControlAltText="Filter Asd column" DataFormatString="{0:MM/dd/yyyy}" ReadOnly="false" HeaderStyle-Width="165px" HeaderStyle-ForeColor="#0000cc">
                    </telerik:GridDateTimeColumn>
                    <telerik:GridBoundColumn DataField="Afd" HeaderText="Actual Finish Date" SortExpression="Afd" UniqueName="Afd" DataType="System.DateTime"
                        FilterControlAltText="Filter Afd column" DataFormatString="{0:MM/dd/yyyy}" ReadOnly="true">
                    </telerik:GridBoundColumn>              
                    <telerik:GridBoundColumn DataField="UpdPcComp" HeaderText="Updated % Comp" SortExpression="UpdPcComp" UniqueName="UpdPcComp" DataType="System.Decimal"
                        FilterControlAltText="Filter UpdPcComp column" ReadOnly="false" HeaderStyle-ForeColor="#0000cc">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="UpdBy" HeaderText="Updated By" SortExpression="UpdBy" UniqueName="UpdBy"
                        FilterControlAltText="Filter UpdBy column" ReadOnly="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="UpdDate" HeaderText="Last Updated" SortExpression="UpdDate" UniqueName="UpdDate" DataType="System.DateTime"
                        FilterControlAltText="Filter UpdDate column" DataFormatString="{0:MM/dd/yyyy}" ReadOnly="true">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
     
    </asp:Content>

    C#: 

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    namespace CobraStatus.aspx
    {
        public partial class CobraStatusTemplate1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                projects();         
            }
            
            private void projects()
            {
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["FinanceSystemsApplicationsConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT ProgramId FROM csProgram ORDER BY ProgramId", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rdlProject.DataSource = dt;
                rdlProject.DataTextField = "ProgramId";
                rdlProject.DataValueField = "ProgramId";
                rdlProject.DataBind();
            }
     
            private void analysts()
            {
                string project = rdlProject.SelectedValue;
     
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["FinanceSystemsApplicationsConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT DISTINCT csCawp.C5, csAnalysts.EmployeeId, csAnalysts.FullName FROM csCawp INNER JOIN " +
                             "csAnalysts ON csCawp.C5 = csAnalysts.EmployeeId WHERE Project = '" + project + "'", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rdlAnalyst.DataSource = dt;
                rdlAnalyst.DataTextField = "FullName";
                rdlAnalyst.DataValueField = "EmployeeId";
                rdlAnalyst.DataBind();
     
            }
     
            private void controlAccount()
            {
                string project = rdlProject.SelectedValue;
                string analyst = rdlAnalyst.SelectedValue;
     
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["FinanceSystemsApplicationsConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT DISTINCT Ca1 FROM CsCAWP WHERE Project = '" + project + "' AND C5 = " + analyst + "", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rcbControlAccount.DataSource = dt;
                rcbControlAccount.DataTextField = "Ca1";
                rcbControlAccount.DataValueField = "Ca1";
                rcbControlAccount.DataBind();         
            }
     
            private void evt()
            {
                string project = rdlProject.SelectedValue;
                string analyst = rdlAnalyst.SelectedValue;          
     
                DataTable dt = new DataTable();
     
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FinanceSystemsApplicationsConnectionString"].ConnectionString))
                {
                    string controlAccount = string.Empty;
                    for (int i = 0; i < rcbControlAccount.CheckedItems.Count; i++)
                    {
                        if (i < rcbControlAccount.CheckedItems.Count - 1)
                        {
                            controlAccount += rcbControlAccount.CheckedItems[i].Value;
                            controlAccount += "'";
                            controlAccount += ",";
                            controlAccount += "'";
                        }
                        else
                        {
                            controlAccount += rcbControlAccount.CheckedItems[i].Value;
                        }
                    }
     
                    conn.Open();
                    
                    SqlCommand cmnd = new SqlCommand("SELECT DISTINCT csEVT.Code, csEVT.Description FROM csCawp INNER JOIN csEVT ON csCawp.Pmt = csEVT.Code " +
                        "WHERE csCawp.Project = '" + project + "' AND csCawp.C5 = '" + analyst + "' AND csCawp.Ca1 IN ('" + controlAccount + "')", conn);
                    SqlDataAdapter adp = new SqlDataAdapter(cmnd);
                    adp.Fill(dt);
                }
                rcbEVT.DataSource = dt;
                rcbEVT.DataTextField = "Description";
                rcbEVT.DataValueField = "Code";
                rcbEVT.DataBind();        
            }
     
     
            protected void rdlProject_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
            {
                analysts();
                rdlAnalyst.Enabled = true;
            }
     
            protected void rdlAnalyst_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
            {
                controlAccount();
                rcbControlAccount.Enabled = true;         
            }
     
            protected void rcbControlAccount_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
            {     
                evt();
                rcbEVT.Enabled = true;
            }
     
            protected void rcbEVT_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
            {
                RadGrid1.Rebind();
            }
     
            public DataTable GetDataTable(string query)
            {
     
                String ConnString = ConfigurationManager.ConnectionStrings["FinanceSystemsApplicationsConnectionString"].ConnectionString;
     
                SqlConnection conn = new SqlConnection(ConnString);
     
                SqlDataAdapter adapter = new SqlDataAdapter();
     
                adapter.SelectCommand = new SqlCommand(query, conn);
     
                DataTable myDataTable = new DataTable();
     
                conn.Open();
     
                try
                {
     
                    adapter.Fill(myDataTable);
     
                }
     
                finally
                {
     
                    conn.Close();
     
                }
     
                return myDataTable;
     
            }
     
            protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
     
                int rcbCA = rcbControlAccount.CheckedItems.Count;
                int rcbEvt = rcbEVT.CheckedItems.Count;
                if (rdlProject.SelectedValue != "" && rdlAnalyst.SelectedValue != "" && rcbCA > 0 && rcbEvt > 0)          
                {             
                    string project = rdlProject.SelectedValue;
                    string analyst = rdlAnalyst.SelectedValue;
                    string controlAccount = string.Empty;
                    for (int i = 0; i < rcbControlAccount.CheckedItems.Count; i++)
                    {
                        if (i < rcbControlAccount.CheckedItems.Count - 1)
                        {
                            controlAccount += rcbControlAccount.CheckedItems[i].Value;
                            controlAccount += "'";
                            controlAccount += ",";
                            controlAccount += "'";
                        }
                        else
                        {
                            controlAccount += rcbControlAccount.CheckedItems[i].Value;
                        }
                    }
     
                    string evt = string.Empty;
                    for (int i = 0; i < rcbEVT.CheckedItems.Count; i++)
                    {
                        if (i < rcbEVT.CheckedItems.Count - 1)
                        {
                            evt += rcbEVT.CheckedItems[i].Value;
                            evt += "'";
                            evt += ",";
                            evt += "'";
                        }
                        else
                        {
                            evt += rcbEVT.CheckedItems[i].Value;
                        }
                    }
                   
                    RadGrid1.DataSource = GetDataTable("SELECT csCawp.Project, csCawp.Ca1, csCawp.Wp, csCawp.Descrip, csEVT.Description, csAnalysts.FullName, csCawp.PcComp," +
                        "csCawp.Ssd, csCawp.Sfd, csCawp.Asd, csCawp.Afd, csCawp.UpdPcComp, csCawp.UpdDate, csCawp.UpdBy FROM csCawp INNER JOIN csEVT ON csCawp.Pmt = csEVT.Code INNER JOIN " +
                        "csAnalysts ON CsCawp.C5 = csAnalysts.EmployeeId  " +
                       " WHERE PROJECT = '" + project + "' AND Ca1 IN ('" + controlAccount + "') AND Pmt IN ('" + evt + "')");              
                }
            }
     
            protected void Button1_Click(object sender, EventArgs e)
            {
     
            }
     
            protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    if (item["PcComp"].Text == "0.000000")
                        item.ForeColor = Color.Red;
                }
            }
     
            protected void RadGrid1_PreRender(object sender, EventArgs e)
            {
                
            }
     
            protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
            {
     
            }
            
     
        }
    }

     

    Thanks in advance,

    Josh 

     

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 09 Apr 2015 Link to this post

    Hello Josh,

    I isolated the RadComboBox and RadDropDownList controls you have in your scenario into a sample runnable project attached to this reply. At my side the selections in all four of them are persisted after performing a postback.

    Could you please review the code and try to reproduce the issue in it? This would help us find what could be causing the selection to be cleared.

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Josh
    Josh avatar
    16 posts
    Member since:
    Feb 2014

    Posted 13 Apr 2015 in reply to Ivan Danchev Link to this post

    Ivan,

     Thank you for the reply and sample project. I have created a new project based on your sample and experience the same issue. I apparently can't attach a sample project through this forum but below is the markup/code I am using. In this project the first three comboboxes maintain their selections the fourth immediately loses its selections.

     Thank you for your help, I look forward to your reply,

     Josh

    ASPX:

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ComboBoxPostBackTest.WebForm1" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
     
        <div>
            <telerik:RadDropDownList ID="rdlProject" runat="server" DefaultMessage="Select Project"
            OnSelectedIndexChanged="rdlProject_SelectedIndexChanged" AutoPostBack="true"  Enabled="true">
        </telerik:RadDropDownList>
      
        <telerik:RadDropDownList ID="rdlAnalyst" runat="server" DefaultMessage="Select Analyst"
            OnSelectedIndexChanged="rdlAnalyst_SelectedIndexChanged" AutoPostBack="true"  Enabled="false">
        </telerik:RadDropDownList>
      
        <telerik:RadComboBox ID="rcbControlAccount" runat="server" Text="Select Control Account" CheckBoxes="true"
            EnableCheckAllItemsCheckBox="true" OnSelectedIndexChanged="rcbControlAccount_SelectedIndexChanged" AutoPostBack="true"
            Enabled="false">
        </telerik:RadComboBox>
      
        <telerik:RadComboBox ID="rcbEVT" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" AutoPostBack="true"
            Enabled="false" OnSelectedIndexChanged="rcbEVT_SelectedIndexChanged">
        </telerik:RadComboBox>
     
        <asp:Button runat="server" ID="Button1" Text="DoPostback" />
        </div>
        </form>
    </body>
    </html>

    C#:

    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.Data.SqlClient;
    using System.Configuration;
     
    namespace ComboBoxPostBackTest
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                projects();
            }
     
            private void projects()
            {
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rdlProject.DataSource = dt;
                rdlProject.DataTextField = "CompanyName";
                rdlProject.DataValueField = "SupplierID";
                rdlProject.DataBind();
            }
     
            private void analysts()
            {
                string project = rdlProject.SelectedValue;
     
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rdlAnalyst.DataSource = dt;
                rdlAnalyst.DataTextField = "CompanyName";
                rdlAnalyst.DataValueField = "SupplierID";
                rdlAnalyst.DataBind();
     
            }
     
            private void controlAccount()
            {
                string project = rdlProject.SelectedValue;
                string analyst = rdlAnalyst.SelectedValue;
     
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rcbControlAccount.DataSource = dt;
                rcbControlAccount.DataTextField = "CompanyName";
                rcbControlAccount.DataValueField = "SupplierID";
                rcbControlAccount.DataBind();
            }
     
            private void evt()
            {
                string project = rdlProject.SelectedValue;
                string analyst = rdlAnalyst.SelectedValue;
     
                DataTable dt = new DataTable();
     
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    string controlAccount = string.Empty;
                    for (int i = 0; i < rcbControlAccount.CheckedItems.Count; i++)
                    {
                        if (i < rcbControlAccount.CheckedItems.Count - 1)
                        {
                            controlAccount += rcbControlAccount.CheckedItems[i].Value;
                            controlAccount += "'";
                            controlAccount += ",";
                            controlAccount += "'";
                        }
                        else
                        {
                            controlAccount += rcbControlAccount.CheckedItems[i].Value;
                        }
                    }
     
                    conn.Open();
     
                    SqlCommand cmnd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", conn);
                    SqlDataAdapter adp = new SqlDataAdapter(cmnd);
                    adp.Fill(dt);
                }
                rcbEVT.DataSource = dt;
                rcbEVT.DataTextField = "CompanyName";
                rcbEVT.DataValueField = "SupplierID";
                rcbEVT.DataBind();
            }
     
     
            protected void rdlProject_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
            {
                analysts();
                rdlAnalyst.Enabled = true;
            }
     
            protected void rdlAnalyst_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
            {
                controlAccount();
                rcbControlAccount.Enabled = true;
            }
     
            protected void rcbControlAccount_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
            {
                evt();
                rcbEVT.Enabled = true;
            }
     
            protected void rcbEVT_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
            {
     
            }
        }
    }

     

  5. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 14 Apr 2015 Link to this post

    Hello Josh,

    Have you tried debugging to see what is going wrong at your side? At my side I don't see any issues with project you posted in your last reply. The SelectedIndex in the RadComboBox and RadDropDownList controls is persisted after postback. Here's a link to a short video showing this using the Visual Studio debugger. Note the value of the rcbEVT.SelectedIndex property in the Watch pane before and after performing a postback.

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  6. Josh
    Josh avatar
    16 posts
    Member since:
    Feb 2014

    Posted 14 Apr 2015 in reply to Ivan Danchev Link to this post

    I have tried debugging on my side and haven't been able to find the problem. I immediately lose all selections. I guess I'll have to look into taking another approach on this one.

    Thanks,

     Josh

  7. Josh
    Josh avatar
    16 posts
    Member since:
    Feb 2014

    Posted 14 Apr 2015 in reply to Ivan Danchev Link to this post

    I have been experimenting with various RadComboBox settings to find a possible solution to my issue. Setting AppendDataBoundItems = "true" keeps the checked items checked but has the undesired issue of duplicating the combobox items in the list with each postback. Still really confused, any help would be greatly appreciated.

    Thanks,

    Josh

     

  8. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 16 Apr 2015 Link to this post

    Hello,

    1. Are you positive that you can reproduce this issue in the project that I attached without doing any modifications to the code?
    2. When you debug the project does rcbEVT.SelectedIndex's value change when you make a selection and until you do a postback and does it go back to -1 afterwards?
    3. Is there any difference when running the project in a different browser?
    4. Please check in your browser's developer tools if you get any js error.

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  9. Josh
    Josh avatar
    16 posts
    Member since:
    Feb 2014

    Posted 16 Apr 2015 in reply to Ivan Danchev Link to this post

    Ivan,

      Your sample project works as expected without making any modifications to the code. Inserting my queries into the code causes the problem. I believe the problem has something to do with the way I am binding the dropdowns and comboboxes but I have yet to track down the issue.

    I am unable to test the project in a different browser due to work policies.

    I am not getting any js errors.

    This is probably poor practice but what I've done is moved the binding of the controls to the Page_Load event rather that on the SelectedIndexChanged event. This is keeping all of the checked items. I will continue to test and see if I can find a better solution. This is what I have currently come up with (I know it's not pretty-but it gets me a lot further than I was):

    C#

    protected void Page_Load(object sender, EventArgs e)
            {
                projects();        
     
                if (rdlProject.SelectedIndex != -1)
                {
                    analysts();
                }
               
                if (rdlAnalyst.SelectedIndex != -1 && rcbControlAccount.Items.Count < 1)
                {
                    controlAccount();              
                }
                if (rcbControlAccount.CheckedItems.Count != 0)
                {
                    if (rcbEVT.CheckedItems.Count > 0)
                    {
                        return;                   
                    }
                    else
                    {
                        evt();
                    }
                }          
            }

    Another issue I am having is that the Empty Message is not displayed on the RadComboBoxes any idea why that might be?

    Thanks,

    Josh

     

  10. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 20 Apr 2015 Link to this post

    Hello Josh,

    I am glad you found a workaround.

    Are you setting the empty message through the corresponding RadComboBox's property in the markup? At my side setting EmptyMessage="Make a selection" displays the message correctly.


    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  11. Josh
    Josh avatar
    16 posts
    Member since:
    Feb 2014

    Posted 20 Apr 2015 in reply to Ivan Danchev Link to this post

    Ivan,

     Setting "Empty Message" is not working on my end.

    <div class="col-md-2">
                <asp:Label ID="Label4" runat="server" Text="Control Account" CssClass="labels labels-primary labels-primary-ca"></asp:Label>
                <telerik:RadComboBox ID="rcbControlAccount" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true"
                    AutoPostBack="true" OnSelectedIndexChanged="rcbControlAccount_SelectedIndexChanged" Enabled="false" Skin="Office2010Black"
                    EmptyMessage="Select Control Account">
                </telerik:RadComboBox>
            </div>
     
            <div class="col-md-2">
                <asp:Label ID="Label3" runat="server" Text="EV Technique" CssClass="labels labels-primary labels-primary-evt"></asp:Label>
                <telerik:RadComboBox ID="rcbEVT" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true"
                    AutoPostBack="true" OnSelectedIndexChanged="rcbEVT_SelectedIndexChanged" Enabled="false" Skin="Office2010Black" EmptyMessage="Select EV Technique">
                </telerik:RadComboBox>
            </div>

    Please see attached picture. 

    Thanks,

  12. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 22 Apr 2015 Link to this post

    Hello,

    I would have to ask you to try to reproduce this issue in the project I sent in one of my previous post, because at my side the empty message is displayed correctly in IE11, Chrome and Firefox.

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  13. Josh
    Josh avatar
    16 posts
    Member since:
    Feb 2014

    Posted 22 Apr 2015 in reply to Ivan Danchev Link to this post

    Ivan,

    I have taken your project and simply added the Empty Message attribute to the RadComboBox and as you can see in the screen shot the message is not displayed.

    This same project also displays the behavior I was experiencing before with the last combobox ("rcbEVT") not maintaining its' checked items. The combobox maintains it's checked items when the "DoPostBack" button is pushed but if I change the selections in the "rcbControlAccount" combobox and then make new selections in rcbEVT the combobox immediately loses its' checked items.

    ASPX: 

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ComboBoxPostBackTest.WebForm1" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
     
        <div>
     
            <telerik:RadDropDownList ID="rdlProject" runat="server" DefaultMessage="Select Project"
            OnSelectedIndexChanged="rdlProject_SelectedIndexChanged" AutoPostBack="true"  Enabled="true">
        </telerik:RadDropDownList>
      
        <telerik:RadDropDownList ID="rdlAnalyst" runat="server" DefaultMessage="Select Analyst"
            OnSelectedIndexChanged="rdlAnalyst_SelectedIndexChanged" AutoPostBack="true"  Enabled="false">
        </telerik:RadDropDownList>
      
        <telerik:RadComboBox ID="rcbControlAccount" runat="server" Text="Select Control Account" CheckBoxes="true"
            EnableCheckAllItemsCheckBox="true" OnSelectedIndexChanged="rcbControlAccount_SelectedIndexChanged" AutoPostBack="true"
            Enabled="false" EmptyMessage="Select">
        </telerik:RadComboBox>
      
        <telerik:RadComboBox ID="rcbEVT" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" AutoPostBack="true"
            Enabled="false" OnSelectedIndexChanged="rcbEVT_SelectedIndexChanged" EmptyMessage="Select">
        </telerik:RadComboBox>
     
        <asp:Button runat="server" ID="Button1" Text="DoPostback" />
        </div>
        </form>
     
        
    </body>
    </html>

    C#:

    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.Data.SqlClient;
    using System.Configuration;
     
    namespace ComboBoxPostBackTest
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                projects();
            }
     
            private void projects()
            {
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rdlProject.DataSource = dt;
                rdlProject.DataTextField = "CompanyName";
                rdlProject.DataValueField = "SupplierID";
                rdlProject.DataBind();
            }
     
            private void analysts()
            {
                string project = rdlProject.SelectedValue;
     
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rdlAnalyst.DataSource = dt;
                rdlAnalyst.DataTextField = "CompanyName";
                rdlAnalyst.DataValueField = "SupplierID";
                rdlAnalyst.DataBind();
     
            }
     
            private void controlAccount()
            {
                string project = rdlProject.SelectedValue;
                string analyst = rdlAnalyst.SelectedValue;
     
                DataTable dt = new DataTable();
     
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
                {
                    con.Open();
     
                    SqlCommand cmd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
                rcbControlAccount.DataSource = dt;
                rcbControlAccount.DataTextField = "CompanyName";
                rcbControlAccount.DataValueField = "SupplierID";
                rcbControlAccount.DataBind();
            }
     
            private void evt()
            {
                string project = rdlProject.SelectedValue;
                string analyst = rdlAnalyst.SelectedValue;
     
                DataTable dt = new DataTable();
     
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
                {
                    string controlAccount = string.Empty;
                    for (int i = 0; i < rcbControlAccount.CheckedItems.Count; i++)
                    {
                        if (i < rcbControlAccount.CheckedItems.Count - 1)
                        {
                            controlAccount += rcbControlAccount.CheckedItems[i].Value;
                            controlAccount += "'";
                            controlAccount += ",";
                            controlAccount += "'";
                        }
                        else
                        {
                            controlAccount += rcbControlAccount.CheckedItems[i].Value;
                        }
                    }
     
                    conn.Open();
     
                    SqlCommand cmnd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", conn);
                    SqlDataAdapter adp = new SqlDataAdapter(cmnd);
                    adp.Fill(dt);
                }
                rcbEVT.DataSource = dt;
                rcbEVT.DataTextField = "CompanyName";
                rcbEVT.DataValueField = "SupplierID";
                rcbEVT.DataBind();
            }
     
     
            protected void rdlProject_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
            {
                analysts();
                rdlAnalyst.Enabled = true;
            }
     
            protected void rdlAnalyst_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
            {
                controlAccount();
                rcbControlAccount.Enabled = true;
            }
     
            protected void rcbControlAccount_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
            {
                evt();
                rcbEVT.Enabled = true;
            }
     
            protected void rcbEVT_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
            {
     
            }
        }
    }

  14. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 24 Apr 2015 Link to this post

    Hello Josh,

    The reason behind the rcbEVT combo box losing its selection when you make another selection in rcbControlAccount is the code you execute in your evt() method. The method gets called when you select an item in rcbControlAccount. Since this action is performing a postback this is equal to rebinding the rcbEVT combo box in the Page_Load event handler the following way:
    protected void Page_Load(object sender, EventArgs e)
    {
        projects();
        if (IsPostBack)
        {
            DataTable dt = new DataTable();
     
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
            {
                conn.Open();
     
                SqlCommand cmnd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", conn);
                SqlDataAdapter adp = new SqlDataAdapter(cmnd);
                adp.Fill(dt);
            }
            rcbEVT.DataSource = dt;
            rcbEVT.DataTextField = "CompanyName";
            rcbEVT.DataValueField = "SupplierID";
            rcbEVT.DataBind();
        }
    }

    This would cause the combo box to lose its selection.

    On the issue with the EmptyMessage not showing, this is unusual because at my side, using the same project, it can't be reproduced. I would suggest you use a workaround, which would have the same effect as setting the EmptyMessage in the markup or in the code-behind:
    function pageLoad() {
        var combo = $find("<% =rcbEVT.ClientID %>");
        combo.get_inputDomElement().value = "Make a selection";
    }

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  15. Josh
    Josh avatar
    16 posts
    Member since:
    Feb 2014

    Posted 27 Apr 2015 in reply to Ivan Danchev Link to this post

    Ivan,

     Your explanation makes sense. How would you suggest binding the combo boxes in this case?

    The "Empty Message" workaround fixes my other problem. Although it is still very strange that setting the EmptyMessage in the markup is not functioning as it should. It works as expected in every other project I am currently working on...

    Thanks again,

    Josh

     

  16. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 29 Apr 2015 Link to this post

    Hello Josh,

    In my opinion, a better approach would be to bind the RadComboBoxes only on the page's first load, instead of binding them on every subsequent postback. For instance, if rcbEVT is bound when the page loads for the first time, you can later enable it when making a selection in rcbControlAccount and any subsequent selection (performing a postback) would not cause it to rebind and lose its own selected/checked items:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
     
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
            {
                conn.Open();
     
                SqlCommand cmnd = new SqlCommand("SELECT [SupplierID], [CompanyName] FROM [Suppliers] ORDER BY [CompanyName]", conn);
                SqlDataAdapter adp = new SqlDataAdapter(cmnd);
                adp.Fill(dt);
            }
            rcbEVT.DataSource = dt;
            rcbEVT.DataTextField = "CompanyName";
            rcbEVT.DataValueField = "SupplierID";
            rcbEVT.DataBind();
        }
        projects();
    }

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017