Hi, I have a simple ASPX page with a RadComboBox. I have noticed that the "ClientState" form data doesn't get added to the request when the form submits unless I have opened the combobox and made a selection. Is there any way to get ClientState to populate without making the user select one of the list items--say a default option?
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
>Test RadComboBox</
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
action
=
"TelerikTest.aspx"
runat
=
"server"
>
<
telerik:RadScriptManager
runat
=
"server"
>
<
Scripts
>
<
asp:scriptreference
assembly
=
"Telerik.Web.UI"
name
=
"Telerik.Web.UI.Common.Core.js"
></
asp:scriptreference
>
<
asp:scriptreference
assembly
=
"Telerik.Web.UI"
name
=
"Telerik.Web.UI.Common.jQuery.js"
></
asp:scriptreference
>
<
asp:scriptreference
assembly
=
"Telerik.Web.UI"
name
=
"Telerik.Web.UI.Common.jQueryInclude.js"
></
asp:scriptreference
>
</
Scripts
>
</
telerik:RadScriptManager
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"RadComboBoxItem1"
Value
=
"RadComboBoxItem1"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"RadComboBoxItem2"
Value
=
"RadComboBoxItem2"
/>
</
Items
>
</
telerik:RadComboBox
>
<
input
id
=
"Button1"
type
=
"submit"
value
=
"submit"
/>
</
form
>
</
body
>
</
html
>
7 Answers, 1 is accepted
Hi Philip,
The ClientState is actually part of the POST, but it is empty. This, however, is not relevant to how you should use the combo box, the ClientState field is reserved for internal usage and the control populates it when needed.
Nevertheless, here is how to force the control to recalculate its state and populate the field:
<script>
function
OnClientLoad(sender,args) {
sender.commitChanges();
}
</script>
<telerik:RadComboBox ID=
"RadComboBox1"
runat=
"server"
OnClientLoad=
"OnClientLoad"
>
<Items>
<telerik:RadComboBoxItem runat=
"server"
Text=
"RadComboBoxItem1"
Value=
"RadComboBoxItem1"
/>
<telerik:RadComboBoxItem runat=
"server"
Text=
"RadComboBoxItem2"
Value=
"RadComboBoxItem2"
/>
</Items>
</telerik:RadComboBox>
<input id=
"Button1"
type=
"submit"
value=
"submit"
/>
As for getting a default item, the following article explains how to do that: http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/radcombobox-items/default-item.
Regards,
Telerik by Progress
Thanks, Marin, I appreciate the reply.
I'm using the ClientState so that I can get the selected value of the item in the RadComboBox in the POST results. Getting it directly from the RadComboBox only gives me the selected text. Is there a better way to get the value without using the SelectedIndexChanged event?
Hi Phillip,
You can take it from the actual input, not from the ClientState if you want to use the Request["inputID"] approach.
I suggest, however, that you use the SelectedItem property of the combo box. Here's a small example
protected
void
Page_Load(
object
sender, EventArgs e)
{
Label1.Text = RadComboBox1.SelectedItem.Value;
}
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
AutoPostBack
=
"true"
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"RadComboBoxItem1"
Value
=
"RadComboBoxItem1"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"RadComboBoxItem2"
Value
=
"RadComboBoxItem2"
/>
</
Items
>
</
telerik:RadComboBox
>
<
asp:Label
ID
=
"Label1"
Text
=
""
runat
=
"server"
/>
Regards, Marin Bratanov
Telerik by Progress
Hello Philip,
My first workaround should help then in case the ClientState is blank in your case. Then, you would need to parse the JSON string in order to extract the value.
Regards,
Telerik by Progress
To the best of my knowledge, there are no plans to change this.
If some change occurs, it will probably consist in adding some information to the client state, so safe parsing should be OK (meaning, rely on the name of the property rather than the index).
Regards,
Telerik by Progress