2

I have a RadCombobox in a user control and I am trying to set the value to null or 0 from Javascript. The following code doesn't work. But it's not showing any error also.

function OnClientSelectedIndexChanged(sender, eventArgs) {
    var item = eventArgs.get_item();
        var ddl = document.getElementById('ctl00_plh1_Test1_Dropdown2_RadComboBox1_DropDown');
        ddl.selectedIndex = 0;

}

<telerik:RadComboBox ID="Dropdown1" runat="server" 
                             NoWrap="true" Width="250" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
                            <CollapseAnimation Duration="200" Type="OutQuint" />
                        </telerik:RadComboBox>



<uc2:RadComboBox ID="Dropdown2" runat="server" DdlAutoWidth="true"></uc2:RadComboBox>
Kevin Babcock
  • 10,187
  • 19
  • 69
  • 89
nav100
  • 2,923
  • 19
  • 51
  • 89

5 Answers5

3

Try this.

var mycombobox = $find("<%= MyUserControl.FindControl("RadComboBox1").ClientID %>");

or

var mycombobox = $find("<%= RadComboBox1").ClientID %>");

mycombobox.clearSelection();

You might need this

<rad:RadScriptBlock runat="server" ID="RadCodeBlock">
   <script type="text/javascript">

   </script>
</rad:RadScriptBlock>
codingbiz
  • 26,179
  • 8
  • 59
  • 96
2

I assume the RadComboBox that will trigger the OnClientSelectedIndexChanged event will have 2 or more RadCombBoxItems, otherwise the event will never be fired as the selected index can never change.

When the event fires, you must get a reference to the RadComboBox control inside your UserControl. To set it's SelectedIndex property to 0 you call the set_selectedIndex() function on the client-side control. Keep in mind that this only sets the SelectedIndex, and does not update the text in the input field of the RadComboBox. If you want to clear that out as well you must call the client-side control's set_text() function.

function onComboBoxSelectedIndexChanged(s, e) {
    var ctrl = '<%= Dropdown2.FindControl("RadComboBox1").ClientID %>';
    if (ctrl) {
        ctrl.set_selectedIndex(0);
        ctrl.set_text('');
    } 
}

Please refer to the documentation on Telerik's website for more information regarding the JavaScript API for the RadCombBox control.

Kevin Babcock
  • 10,187
  • 19
  • 69
  • 89
0

What do you want to set to 0 or null the selected value or selected index?
Try this for the selected value:

$find("<%=ctl00_plh1_Test1_Dropdown2_RadComboBox1_DropDown.ClientID%>").set_text("0");
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
0

Try this for the selected value in javascript:

var SelectdVal=1;
$find("<%= YourRadComboBox.ClientID %>").findItemByValue(SelectdVal).select();
-1

Try:

var radComboBox = <%=YourComboBox.ClientID %>;  

radComboBox.SetValue("someValue"); 
Richard
  • 5,810
  • 6
  • 29
  • 36