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

2010.1.415 RadComboBox - automatic load on demand broken after any postback

11 Answers 296 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
theksmith
Top achievements
Rank 1
theksmith asked on 17 Apr 2010, 02:20 AM
load on demand only works on first page load, then if you select an item in the combobox, and then do anything that causes a postback, the combobox will now only have the item you chose in it and the "show more results" box no longer works.

 you can recreate on your own demos...
1 - go here: http://demos.telerik.com/aspnet-ajax/combobox/examples/loadondemand/automaticloadondemand/defaultcs.aspx
2 - choose something in the combobox
3 - click on the "change skin" drop down and pick a new skin (thereby causing a postback)
4 - the demo combobox no longer shows anything but your selected item and the load on demand feature no longer works

11 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 19 Apr 2010, 09:40 AM
Hello theksmith,

This is an expected behavior. After a postback Items loaded on demand are lost and when you open the RadComboBox only the previously selected Item loads. If you type something in the input you will see that the Load On Demand works normally.

Please let me know if I am missing something.

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
theksmith
Top achievements
Rank 1
answered on 19 Apr 2010, 09:18 PM
how can i get the combobox back to working like it does on first load after post back, but with the selected item still there? or at least can i get the "show more results box" to still work after post back, that no longer works, nor virtual scrolling? thanks
0
Simon
Telerik team
answered on 21 Apr 2010, 11:37 AM
Hello theksmith,

You can handle the client-side ItemsRequesting event in this way:
function onItemsRequesting(sender, eventArgs) {
    if (sender.get_items().get_count() == 0)
        eventArgs.get_context()["Text"] = "";
    else
        eventArgs.get_context()["Text"] = sender.get_text();
}

Then, in the server-side ItemsRequested you can filter data based on the e.Context["Text"] value.

I hope this meets your requirement.

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
wai kit
Top achievements
Rank 1
answered on 11 Aug 2010, 10:05 AM
Hi Telerik Support,

I've faced the same problem as posted by theksmith and had tried to solve the problem using the method provided. However, it didn't help much.

Load on demand only works on first page load, then if you select an item in the combobox, and then do anything that causes a postback, the combobox will now only have the item per request if my total number of value is greater than my item per request's value and the "show more results" box no longer works.

Steps to reproduce my problems:
1. go here http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultvb.aspx
2. set the AutoPostBack="true" for RadComboBox2 and OnClientItemsRequesting="onItemsRequesting"

function onItemsRequesting(sender, eventArgs) { 
    if (sender.get_items().get_count() == 0) 
        eventArgs.get_context()["Text"] = ""; 
    else 
        eventArgs.get_context()["Text"] = sender.get_text(); 
}
3. Filter the data based on the e.Context("Text") value in the server side ItemsRequested

Protected Sub RadComboBox2_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
            Dim data As DataTable = GetData(e.Context("Text")) 'GetData(e.Text)
  
            Dim itemOffset As Integer = e.NumberOfItems
            Dim endOffset As Integer = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count)
            e.EndOfItems = endOffset = data.Rows.Count
  
            For i As Integer = itemOffset To endOffset - 1
                RadComboBox2.Items.Add(New RadComboBoxItem(data.Rows(i)("CompanyName").ToString(), data.Rows(i)("CompanyName").ToString()))
            Next
  
            e.Message = GetStatusMessage(endOffset, data.Rows.Count)
        End Sub

*combobox referring to RadComboBox2

You'll notice that for the first time the page loads, and clicks on the combobox, it will loads the value and "ShowMoreResults" box working fine. Proceed by scrolling the combobox and the value will loads without fail. Next, selects a value in the combobox. This will caused a postback to the page. Then, clicks the combobox again to populate the value, and proceed by scrolling. You'll notice that only the number of values in the ItemsPerRequest are loaded while the "ShowMoreResults" no longer works fine.

How can i get the combobox back to working like it does on first load after post back, but with the selected item still there and the "show more results box" still work after post back, and the list populates properly after scrolling? Any help will be highly appreciated. Thanks. 
0
Simon
Telerik team
answered on 16 Aug 2010, 12:24 PM
Hi wai kit,

The behavior you are describing is normal because after postback all Load On Demand Items are lost. Then, after the postback, the RadComboBox is empty and when you open it, it loads on the Item matching the current text.

In order to load new Items and use the 'show more results' functionality you need to delete the text and start typing again.

I hope this helps.

Greetings,
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
theksmith
Top achievements
Rank 1
answered on 16 Aug 2010, 10:55 PM
I think we are getting at the fact that even if this behavior is "by design" it's a poor design that results in a pretty much useless feature.

Why can't the "show more results" feature still work after selecting and item and doing a postback?

Furthermore... "In order to load new Items and use the 'show more results' functionality you need to delete the text and start typing again." - how would an end user ever know to do this? This work-around is not intuitive and therefore not really and option.

I would really appreciate if you could please fix the control so that after postback it shows your selected item and the "show more results" and load-on-demand features still work.

Thank you for your consideration.
0
Simon
Telerik team
answered on 17 Aug 2010, 02:50 PM
Hello theksmith,

The Load On Demand feature by design fires an Items request automatically in the following cases:
  • The RadComboBox is empty when its drop down is opened.
  • The user types in the input of the RCB.
After postback however these Items are lost, so the only data RCB retains is its Text and SelectedValue (Value on the client) properties. So after postback, the control does not have any Items. When you open it then, its Text (which is the previously selected Item's Text) is sent in the ItemsRequested event handler, which causes the behavior in question.

Now, if we want to resolve this we would fire the Items request whenever the RCB is empty with an empty string. However what should happen if the developer wants to have some text written in the input of the RCB when the page loads so that when the RCB is opened it automatically loads Items filtered by this text? It is either this or the other way and the logic depends on the requirements. Additionally the 'by design' behavior is the more common one.

In this sense, you can use the workaround provided earlier in this forum thread when you need the latter behavior.

All the best,
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
Eric
Top achievements
Rank 2
answered on 27 Jan 2011, 09:16 PM

Hi all, actually I got it working. The following code summarizes how I did it:

Markup:

<telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientSelectedIndexChanging="Load1" OnItemsRequested="RadComboBox1_ItemsRequested">
</telerik:RadComboBox>
<telerik:RadComboBox ID="RadComboBox2" runat="server" OnClientSelectedIndexChanging="Load2" OnClientItemsRequested="ItemsLoaded" OnItemsRequested="RadComboBox2_ItemsRequested">
</telerik:RadComboBox>
<telerik:RadComboBox ID="RadComboBox3" runat="server" OnClientItemsRequested="ItemsLoaded"  OnItemsRequested="RadComboBox3_ItemsRequested" OnClientSelectedIndexChanged="LoadData">
</telerik:RadComboBox>
<script type="text/javascript">
    function Load1(combo, eventArgs)
    {
        var combo1 = $find("<%= RadComboBox2.ClientID %>");
        var combo2 = $find("<%= RadComboBox3.ClientID %>");
        var item = eventArgs.get_item();
        combo1.set_text("Loading...");
        combo2.clearSelection();
  
        if (item.get_index() > 0)
        {
            combo1.requestItems(item.get_value(), false);
        }
        else
        {
            combo1.set_text(" ");
            combo1.clearItems();
  
            combo2.set_text(" ");
            combo2.clearItems();
        }
    }
    function Load2(combo, eventArgs)
    {
        var combo2 = $find("<%= versionList.ClientID %>");
        combo2.set_text("Loading...");
        combo2.requestItems(eventArgs.get_item().get_value(), false);
    }
    function ItemsLoaded(combo, eventArgs)
    {
        if (combo.get_items().get_count() > 0)
        {
            combo.set_text(combo.get_items().getItem(0).get_text());
            combo.get_items().getItem(0).highlight();
            combo.showDropDown();
        }
    }
    function LoadData(combo, eventArgs)
    {
        $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("LoadData");
    }
</script>
<telerik:RadAjaxManagerProxy runat="server" ID="RadAjaxManagerProxy1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManagerProxy1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="radGrid"/>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManagerProxy>

C#:

protected override void OnLoad(EventArgs e)
{            
    base.OnLoad(e);
  
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    manager.AjaxRequest += manager_AjaxRequest;
}
protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    //bind combo
}
protected void RadComboBox2_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    //bind combo
}
protected void RadComboBox3_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    //bind combo
}
protected void manager_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
    if (e.Argument == "LoadData")
    {
        //bind grid
    }
}

Hope this helps!

Eric

0
Sravan
Top achievements
Rank 1
answered on 13 Aug 2012, 03:09 PM
Is There Any Other Solution For This ?.
0
Sravan
Top achievements
Rank 1
answered on 13 Aug 2012, 03:09 PM
Is There Any Other Solution For This ?.
0
Kalina
Telerik team
answered on 14 Aug 2012, 01:41 PM
Hello Sravan,

Can you explain in more details what the issue that you face is?

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.
Tags
ComboBox
Asked by
theksmith
Top achievements
Rank 1
Answers by
Simon
Telerik team
theksmith
Top achievements
Rank 1
wai kit
Top achievements
Rank 1
Eric
Top achievements
Rank 2
Sravan
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or