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

RadComboBox ClientState form data is empty on form submit

7 Answers 251 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Philip D
Top achievements
Rank 1
Philip D asked on 04 Apr 2017, 08:33 PM

 

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>
<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

Sort by
0
Marin Bratanov
Telerik team
answered on 07 Apr 2017, 02:22 PM

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,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Philip D
Top achievements
Rank 1
answered on 07 Apr 2017, 04:02 PM

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?

0
Marin Bratanov
Telerik team
answered on 10 Apr 2017, 10:22 AM

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Philip D
Top achievements
Rank 1
answered on 10 Apr 2017, 02:14 PM
In this case, though, that property isn't available.  This isn't a postback, it's a report selection screen and the form data is going to a different page.
0
Marin Bratanov
Telerik team
answered on 12 Apr 2017, 07:26 AM

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,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Philip D
Top achievements
Rank 1
answered on 12 Apr 2017, 10:17 AM
Yeah, that's what I've been doing.  I just want to make sure that using the ClientState like this is not some unsupported feature--I'd hate to have to go back and rewrite it somewhere down the road.  How possible do you think that is?
0
Marin Bratanov
Telerik team
answered on 12 Apr 2017, 10:23 AM

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,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Philip D
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Philip D
Top achievements
Rank 1
Share this question
or