RadComboBox ClientState form data is empty on form submit

8 posts, 0 answers
  1. Philip D
    Philip D avatar
    4 posts
    Member since:
    May 2006

    Posted 04 Apr 2017 Link to this post

     

    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>
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5128 posts

    Posted 07 Apr 2017 Link to this post

    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.
  3. Philip D
    Philip D avatar
    4 posts
    Member since:
    May 2006

    Posted 07 Apr 2017 in reply to Marin Bratanov Link to this post

    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?

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5128 posts

    Posted 10 Apr 2017 Link to this post

    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.
  5. Philip D
    Philip D avatar
    4 posts
    Member since:
    May 2006

    Posted 10 Apr 2017 in reply to Marin Bratanov Link to this post

    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.
  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5128 posts

    Posted 12 Apr 2017 Link to this post

    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.
  7. Philip D
    Philip D avatar
    4 posts
    Member since:
    May 2006

    Posted 12 Apr 2017 in reply to Marin Bratanov Link to this post

    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?
  8. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5128 posts

    Posted 12 Apr 2017 Link to this post

    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.
Back to Top