Hi,
My ComboBox looks like this:
When I click on a button, I call a javacript method that do:
It calls the ItemRequested on the server and it correctly find the item I want. But it doesn't refresh my ComboBox on the client, so it stays empty.
What am I doing wrong?
My ComboBox looks like this:
<
telerik:RadComboBox
ID
=
"cboChambreDe"
runat
=
"server"
MarkFirstMatch
=
"True"
EnableLoadOnDemand
=
"True"
HighlightTemplatedItems
=
"True"
Height
=
"300px"
LoadingMessage
=
"Chargement"
ItemsPerRequest
=
"10"
ShowMoreResultsBox
=
"true"
EnableVirtualScrolling
=
"true"
OnItemsRequested
=
"cboChambre_ItemsRequested"
DropDownWidth
=
"300"
>
</
telerik:RadComboBox
>
When I click on a button, I call a javacript method that do:
$find(
"cboChambreDe"
).requestItems(
"TOM1"
,
false
);
It calls the ItemRequested on the server and it correctly find the item I want. But it doesn't refresh my ComboBox on the client, so it stays empty.
What am I doing wrong?
6 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 21 Jun 2012, 04:42 AM
Hi Jocelyn,
The items added in the ItemsRequested event persist only at the client-side. This is done for a better performance. These items will disappear after postback. Here postback on your button click is clearing the item.If you need the items to persist at the server, you need to add them outside the ItemsRequested event.
Thanks,
Princy.
The items added in the ItemsRequested event persist only at the client-side. This is done for a better performance. These items will disappear after postback. Here postback on your button click is clearing the item.If you need the items to persist at the server, you need to add them outside the ItemsRequested event.
Thanks,
Princy.
0
Hi Jocelyn,
Please make sure that you use cboChambreDe.ClientID when you try to obtain the RadComboBox client-side object
Additionally you can check whether the request for items returns any data.
All the best,
Kalina
the Telerik team
Please make sure that you use cboChambreDe.ClientID when you try to obtain the RadComboBox client-side object
<
script
type
=
"text/javascript"
>
function showItems() {
var combo = $find("<%=cboChambreDe.ClientID %>");
combo.requestItems("Tom1", false);
}
</
script
>
<
telerik:RadComboBox
ID
=
"cboChambreDe"
runat
=
"server"
EnableLoadOnDemand
=
"True"
HighlightTemplatedItems
=
"True"
Height
=
"300px"
LoadingMessage
=
"Chargement"
ItemsPerRequest
=
"10"
ShowMoreResultsBox
=
"true"
EnableVirtualScrolling
=
"true"
OnItemsRequested
=
"cboChambre_ItemsRequested"
DropDownWidth
=
"300"
>
</
telerik:RadComboBox
>
<
input
type
=
"button"
onclick
=
"showItems()"
value
=
"click"
/>
protected
void
cboChambre_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
RadComboBox combo = (RadComboBox)sender;
combo.Items.Add(
new
RadComboBoxItem(e.Text));
}
Additionally you can check whether the request for items returns any data.
All the best,
Kalina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jocelyn
Top achievements
Rank 1
answered on 26 Jun 2012, 02:18 PM
How can I select the item I just added after the requestItems?
I tired to do:
But when select() is executed, my item is not added yet.
Edit: And what is the proper way to call a resquesItem server side?
For the moment, I am doing it like this:
But I don't get the same behavior as if a user was entering a text in the combo box. Example, even though I set the e.Message, on client side, the message is still empty. Also, it correctly loads 10 items, but the requestResquested event is never fired until the user enter a new text in the combo box and I know that there is more than 10 items overall.
Thanks.
I tired to do:
<script type=
"text/javascript"
>
function
showItems()
{
var
combo = $find(
"<%=cboChambreDe.ClientID %>"
);
combo.requestItems(
"Tom1"
,
false
);
combo.get_items().getItem(0).select();
}
</script>
But when select() is executed, my item is not added yet.
Edit: And what is the proper way to call a resquesItem server side?
For the moment, I am doing it like this:
Dim
e
As
RadComboBoxItemsRequestedEventArgs =
New
RadComboBoxItemsRequestedEventArgs()
e.Text =
""
cboChambreDe.Text =
""
cboChambreDe_ItemsRequested(cboChambreDe, e)
But I don't get the same behavior as if a user was entering a text in the combo box. Example, even though I set the e.Message, on client side, the message is still empty. Also, it correctly loads 10 items, but the requestResquested event is never fired until the user enter a new text in the combo box and I know that there is more than 10 items overall.
Thanks.
0
Accepted
Hi Jocelyn,
The invocation of requestItems method will result in a callback to the server which will then fire the ItemsRequested server side event. The appropriate event for selection of a specific item is the OnClientItemsRequested, which is fired immediately after the request for items is finished thus ensuring that the items are already loaded. Here is a sample implementation:
As for the ItemsRequested event, it's not appropriate to manually invoke it from code behind. It's will be automatically fired when a request for items is being made.
Kind regards,
Nencho
the Telerik team
The invocation of requestItems method will result in a callback to the server which will then fire the ItemsRequested server side event. The appropriate event for selection of a specific item is the OnClientItemsRequested, which is fired immediately after the request for items is finished thus ensuring that the items are already loaded. Here is a sample implementation:
function
AddNewItem()
{
var
combo = $find(
"<%= RadComboBox1.ClientID %>"
);
combo.requestItems(
"Item1"
,
true
);
}
function
onClientItemsRequested(sender, args)
{
sender.get_items().getItem(0).select();
}
As for the ItemsRequested event, it's not appropriate to manually invoke it from code behind. It's will be automatically fired when a request for items is being made.
Kind regards,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jocelyn
Top achievements
Rank 1
answered on 27 Jun 2012, 06:38 PM
Thanks Nencho!
It works, but except for one scenario. If I call showItem() on a RadButton that have AutoPostBack set to true, the OnClientItemRequested is not called. Is there a way that I can achieve this or AutoPostBack must be set to false?
Thanks.
It works, but except for one scenario. If I call showItem() on a RadButton that have AutoPostBack set to true, the OnClientItemRequested is not called. Is there a way that I can achieve this or AutoPostBack must be set to false?
Thanks.
0
Accepted
Hello Joceyn,
Thank you for getting back to me.
The items loaded on demand are not persisted after post-back thus populating the RadComboBox by clicking a button which performs a post back is not a good approach.
Greetings,
Nencho
the Telerik team
Thank you for getting back to me.
The items loaded on demand are not persisted after post-back thus populating the RadComboBox by clicking a button which performs a post back is not a good approach.
Greetings,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.