Set RadComboBox to empty clientside

8 posts, 0 answers
  1. Craig
    Craig avatar
    20 posts
    Member since:
    Aug 2006

    Posted 16 Feb 2010 Link to this post

    Is there a way to set a combo box to "empty" on the client? I mean empty like when the page is first loaded with nothing in it and the empty message is showing.

    Through client side code I can clear items, clear selection and even set the combo text. But I can not figure out how to get it back to the initial "empty" state through code. If I manually delete the text in the combo box it shows the empty message but I can't seem to set it through code.

    I have linked combo's and if the user clears the parent then the child needs to be cleared (set to empty) and disabled.

    I have resulted to clearing the items and setting the text to "select an item". My biggest issue is that the text looks different than the empty message text. Users pick up on that stuff.

    This seems like an obvious thing to have. It would be nice if there was a method that set the combo to empty like:
    combo.set_empty();
    I thought the clearItems method would have done this but it just leaves the text in the combo blank.

    Any help would be appreciated.

    Thanks,
    Craig
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Feb 2010 Link to this post

    Hello Craig,

    Try setting EmptyMessage explicitly from client-side after clearing the combobox text.

    JavaScript:
     
        function setEmpty() { 
            var combo = $find('<%= RadComboBox1.ClientID %>'); 
            combo.clearSelection(); 
            combo.set_emptyMessage("Select an item"); 
        } 

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Craig
    Craig avatar
    20 posts
    Member since:
    Aug 2006

    Posted 19 Feb 2010 Link to this post

    Shinu,

    Thanks for taking a shot. Ultimatly that is what I ended up doing. It works but the style of the text is just differnt. I hope the customer doesn't care (i'm not even going to bring it up).

    Drop a combo on the page and set the emty text to "select an item" and throw in a few items. Open the the page and look at the text. It's greyed out in italics (i'm using the simple skin).

    Now select and item. The item text is different (as it should be). Now delete the item text and move off the control. The combo is back to the empty text format and string.

    When I try to do this thorough code I can't get the formating back (greyed out with italics). If you set the text to "" it's just balnk. If you specify the text to be "select an item" it looks like the item text. I guess I could hack around for a few hours and try and figure out what css to call and set it client side but that is just not happening right now.

    It seems to me that the most intuitive thing is set the combo text to "" and it should show the empty text in the correct format.

    I'm not a designer so I can live with it but I have some buddies that would be all over this.

    Thanks
    Craig
  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 25 Feb 2010 Link to this post

    Hi Craig,

    You can explicitly apply the empty message after setting the text of the RadComboBox to an empty string by calling _applyEmptyMessage().

    Best wishes,
    Simon
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Cliff Gibson
    Cliff Gibson avatar
    45 posts
    Member since:
    Oct 2009

    Posted 02 Dec 2010 Link to this post

    Hi

    Is it possible to do something similar to _applyEmptyMessage() in the c# code behind...?

    I've currently got:

     

    ddAreas.SelectedValue = string.Empty;
    ddAreas.ClearSelection();

    but it is not reverting the combo back to the empty message.

    Cheers
    Cliff
  7. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 03 Dec 2010 Link to this post

    Hello Cliff Gibson,

    In order to apply the empty message server-side the RadComboBox should allow custom text. The easiest way to enable this is to set the AllowCustomText property to true.

    I hope this helps.

    Kind regards,
    Simon
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  8. Rahul
    Rahul avatar
    39 posts
    Member since:
    Jan 2014

    Posted 12 Jan 2014 Link to this post

    Hi Shinu,
                         on which event this function call?
    Thanks,
    Rahul
  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Jan 2014 Link to this post

    Hi Rahul,

    I guess you want to show the EmptyMessage of RadComboBox from Client Side. Please have a look into the following code snippet to show the EmptyMessage of RadComboBox on RadButton OnClientClicked event.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" EmptyMessage="Select an item">
        <Items>
            <telerik:RadComboBoxItem Text="Item1" />
            <telerik:RadComboBoxItem Text="Item2" />
            <telerik:RadComboBoxItem Text="Item3" />
            <telerik:RadComboBoxItem Text="Item4" />
        </Items>
    </telerik:RadComboBox>
    <telerik:RadButton ID="RadButton1" runat="server" Text="SetEmpty" AutoPostBack="false"
        OnClientClicked="setEmpty">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function setEmpty() {
            var combo = $find('<%= RadComboBox1.ClientID %>');
            combo.clearSelection();
            combo.set_emptyMessage("Select an item");
        }
    </script>

    Please elaborate your requirement if it doesn't help.
    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017