Is there a way to hide the second combobox without setting Visible=false on the server so that the object can be retrieved on the client?
8 Answers, 1 is accepted
One suggestion is setting the visibility of second RadComboBox to false inside the pageLoad() function instead of setting it from server. Try the client side code shown below.
[ASPX]
<telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"> |
<Items> |
<telerik:RadComboBoxItem Text=" item1" /> |
<telerik:RadComboBoxItem Text=" item2" /> |
</Items> |
</telerik:RadComboBox> |
<telerik:RadComboBox ID="RadComboBox2" runat="server"> |
</telerik:RadComboBox> |
[CS]
<script type="text/javascript"> |
function pageLoad() |
{ |
var combo = $find("<%= RadComboBox2.ClientID %>"); |
combo.set_visible(false); // Hide the Combo when page loads |
} |
function OnClientSelectedIndexChanged() |
{ |
var combo = $find("<%= RadComboBox2.ClientID %>"); |
combo.set_visible(true); |
} |
</script> |
Thanks,
Shinu.
Adisa
You could toggle the display CSS property of its container between "none" and an empty string.
The following works fine for me, though:
<telerik:RadComboBox ID=
"RadComboBox1"
runat=
"server"
OnClientSelectedIndexChanged=
"OnClientSelectedIndexChanged"
>
<Items>
<telerik:RadComboBoxItem Text=
" item1"
/>
<telerik:RadComboBoxItem Text=
" item2"
/>
</Items>
</telerik:RadComboBox>
<telerik:RadComboBox ID=
"RadComboBox2"
runat=
"server"
>
</telerik:RadComboBox>
<script type=
"text/javascript"
>
function
pageLoad() {
var
combo = $find(
"<%= RadComboBox2.ClientID %>"
);
combo.set_visible(
false
);
// Hide the Combo when page loads
}
function
OnClientSelectedIndexChanged() {
var
combo = $find(
"<%= RadComboBox2.ClientID %>"
);
combo.set_visible(
true
);
var
comboItem =
new
Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(
"New Item"
);
combo.trackChanges();
combo.get_items().add(comboItem);
comboItem.select();
combo.commitChanges();
}
</script>
So if it doesn't work for you or your case is different, can you modify this sample to showcase the issue? Also, can you confirm you are using the latest version of the UI for ASP.NET AJAX controls?
Also, if you are looking to populate a combo box on demand, it offers such features out of the box: https://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx. You can trigger loading of items through its client-side API as well, see the .requestItems(text, shouldAppend) method and Example 4: https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/client-side-programming/objects/radcombobox-object.
Regards,
Marin Bratanov
Progress Telerik
Then you will need to write some logic in the OnClientSelectedIndexChanged handler that determines whether to hide or not the other control.
Regards,
Marin Bratanov
Progress Telerik