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

Set RadComboBox to empty clientside

7 Answers 2096 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 16 Feb 2010, 06:32 PM
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

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Feb 2010, 05:18 AM
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.
0
Craig
Top achievements
Rank 1
answered on 20 Feb 2010, 01:07 AM
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
0
Simon
Telerik team
answered on 25 Feb 2010, 12:24 PM
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.
0
Cliff Gibson
Top achievements
Rank 1
answered on 02 Dec 2010, 06:03 PM
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
0
Simon
Telerik team
answered on 03 Dec 2010, 06:29 PM
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.
0
Rahul
Top achievements
Rank 1
answered on 12 Jan 2014, 09:19 AM
Hi Shinu,
                     on which event this function call?
Thanks,
Rahul
0
Shinu
Top achievements
Rank 2
answered on 13 Jan 2014, 02:52 AM
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.
Tags
ComboBox
Asked by
Craig
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Craig
Top achievements
Rank 1
Simon
Telerik team
Cliff Gibson
Top achievements
Rank 1
Rahul
Top achievements
Rank 1
Share this question
or