Reputation: 3133
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>
Upvotes: 2
Views: 23283
Reputation: 129
Try this for the selected value in javascript:
var SelectdVal=1;
$find("<%= YourRadComboBox.ClientID %>").findItemByValue(SelectdVal).select();
Upvotes: 0
Reputation: 1
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");
Upvotes: 0
Reputation: 10247
I assume the RadComboBox
that will trigger the OnClientSelectedIndexChanged
event will have 2 or more RadCombBoxItem
s, 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.
Upvotes: 2
Reputation: 5998
Try:
var radComboBox = <%=YourComboBox.ClientID %>;
radComboBox.SetValue("someValue");
Upvotes: -1
Reputation: 26386
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>
Upvotes: 3