RadComboBox in Sitefinity looses selected item/value

8 posts, 1 answers
  1. Jacques
    Jacques avatar
    138 posts
    Member since:
    Jun 2007

    Posted 26 Apr 2012 Link to this post

    Hi there,

    I have a pretty simple search form as follows:

    <asp:Label ID="Label1" AssociatedControlID="ZipOrCityState" runat="server">Zip or City, State</asp:Label>
    <telerik:RadTextBox ID="RadTextBox1" runat="server" EnableEmbeddedBaseStylesheet="false"
        EnableEmbeddedSkins="false" TabIndex="1" EnableSingleInputRendering="true" Width="217px">
    </telerik:RadTextBox>
    <asp:Label ID="Label2" AssociatedControlID="CompanyList" runat="server">Company</asp:Label>
    <telerik:RadComboBox ID="RadComboBox1" runat="server" EnableEmbeddedBaseStylesheet="False"
        EnableEmbeddedSkins="False" TabIndex="2" EnableSingleInputRendering="true" Width="217px"
        DataSourceID="CompanyDataSource" AllowCustomText="false" DataTextField="CompanyName"
        DataValueField="CompanyId" EnableViewState="true">
    </telerik:RadComboBox>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetCompanyComboList"
        TypeName="Web.Offices.OfficeManager"></asp:ObjectDataSource>
    <div class="officeSearchResultsButton">
        <telerik:RadButton ID="RadButton1" runat="server" Text="Search" CssClass="blueButton"
            OnClick="Search_Click" TabIndex="25" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins="false"
            ValidationGroup="ValidOfficeSearch">
        </telerik:RadButton>
    </div>

    With C# in the back that looks like this: 
    #region EVENTHANDLER - Page_Load
     protected void Page_Load(object sender, EventArgs e)
     {
         try
         {
             if (!IsPostBack)
             {
                 //Populate controls from values passed from calling page in the query string
                 ZipOrCityState.Text = Request.QueryString["zipOrCityState"];
                 CompanyList.SelectedValue = Request.QueryString["companyId"];
     
                 //Bind Offices Grid
                 OfficeGrid.DataBind();
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     #endregion
     #region EVENTHANDLER - Search_Click
     protected void Search_Click(object sender, EventArgs e)
     {
         try
         {
             //Check if submitted data is valid
             if (Page.IsValid)
             {
                 //Bind Offices Grid
                 OfficeGrid.DataBind();
             }
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             throw ex;
         }
     }
     #endregion

    If we choose a company from the list (blank zip field) and click search the results come back correct and the company name is persisted as the selected item, but if you just click search again without changing anything the combo box looses the selected item value and resets back to index 0. 

    I'm using an ObjectDataSource so why would this happen? I'm not manually calling DataBind for this RadComboBox anywhere? 

    Regards,
    Jacques
  2. Jacques
    Jacques avatar
    138 posts
    Member since:
    Jun 2007

    Posted 27 Apr 2012 Link to this post

    Anyone out there that can help? 
  3. Jacques
    Jacques avatar
    138 posts
    Member since:
    Jun 2007

    Posted 28 Apr 2012 Link to this post

    Can anyone help me with this? 
  4. Answer
    Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 30 Apr 2012 Link to this post

    Hi Jacques,

    The RadComboBox does not persist its selected value indeed. It has to do with the ViewState of the control.
    The following, however,  should be enough to overcome this behavior:
    <telerik:RadComboBox ID="RadComboBox2" runat="server" Height="200px" Width="220px"
        OnClientLoad="function (sender, args){sender.updateClientState();}" >
    </telerik:RadComboBox>

    I hope this helps.

    Regards,
    Ivana
    the Telerik team
    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 their blog feed now.
  5. Jacques
    Jacques avatar
    138 posts
    Member since:
    Jun 2007

    Posted 01 May 2012 Link to this post

    This answer worked, but I'd be interested to know why one would have to do that? 

    The default behaviour of an asp.net control is to use view and control state for this very purpose, so why with the Telerik RadCombo would you have to add custom client side code to do what Asp.net already does? 

    Thanks for the help. 
  6. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 02 May 2012 Link to this post

    Hi Jaques,

    This has to do with Sitefinity itself where by default the ViewState is disabled. Simply setting the EnableViewState property of RadComboBox  to True will not help in this case since the control's ViewState configuration will be overridden by the page's configuration in which the control is defined.

    Greetings,
    Ivana
    the Telerik team
    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 their blog feed now.
  7. Justin
    Justin avatar
    4 posts
    Member since:
    Sep 2012

    Posted 25 Oct 2012 Link to this post

    I am having a similar problem, I use the selected value of my radcombobox to query my DB (connected via Entity Framework to DB).  I have a search button that when clicked takes the radcombobox.selectedvalue and performs the query.  The results are displayed in a RadGrid.  This intial load of the data works fine, it is when I use the page size selector (combobox) built into the radgrid that the selected value from the combobox is flushed.  This functionality should be build into the control, I should not have to write more code with the Telerik control than I do with the ASP.NET control to perform simple data persistence.  What can I do to persist this data?
  8. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 30 Oct 2012 Link to this post

    Hello Justin,

    I have noticed that you have reported a similar problem in this forum thread here, so could you clarify whether the problem reported here is the same as the one from the aforementioned forum thread? My suggestion is to open a support ticket and provide a runnable sample reproducing the issue so we could inspect it and help you troubleshoot it.

    All the best,
    Dimitar Terziev
    the Telerik team
    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 their blog feed now.
Back to Top