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

RadComboBox in Sitefinity looses selected item/value

7 Answers 182 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jacques
Top achievements
Rank 2
Jacques asked on 26 Apr 2012, 01:52 PM
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

7 Answers, 1 is accepted

Sort by
0
Jacques
Top achievements
Rank 2
answered on 27 Apr 2012, 02:37 PM
Anyone out there that can help? 
0
Jacques
Top achievements
Rank 2
answered on 28 Apr 2012, 02:44 PM
Can anyone help me with this? 
0
Accepted
Ivana
Telerik team
answered on 30 Apr 2012, 12:29 PM
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.
0
Jacques
Top achievements
Rank 2
answered on 01 May 2012, 10:15 AM
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. 
0
Ivana
Telerik team
answered on 02 May 2012, 03:49 PM
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.
0
Justin
Top achievements
Rank 1
answered on 25 Oct 2012, 04:28 PM
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?
0
Dimitar Terziev
Telerik team
answered on 30 Oct 2012, 12:13 PM
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.
Tags
ComboBox
Asked by
Jacques
Top achievements
Rank 2
Answers by
Jacques
Top achievements
Rank 2
Ivana
Telerik team
Justin
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or