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

2010 Q1SP1 - OnItemsRequested Not Firing When In ListBox ItemTemplate

8 Answers 139 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
WRONG ACCOUNT
Top achievements
Rank 1
WRONG ACCOUNT asked on 11 May 2010, 07:01 PM
I have a ComboBox located in the ItemTemplate for a ListBox, and it was working fine prior to updating to the 2010 Quarter 1 Service Pack 1 version. Now, OnItemsRequested is not firing and I get an error saying "The target 'blah' for the callback could not be found or did not implement ICallbackEventHandler" when the control requests items.

If I move the ComboBox outside of the ItemTemplate, it works just fine. It's only when it's within the ListBox. Below is my code. By way of explanation, I'm doing it this way in order to show the the EmptyMessage, and then load the items after, so that it doesn't select the first item.

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"
    <script type="text/javascript"
        function LoadFieldCombo(sender, args) { 
            sender.requestItems("", true); 
        } 
    </script> 
</telerik:RadScriptBlock> 
     
<telerik:RadDock ID="UserDefinedFieldsDock" runat="server" Title="User Defined Fields" 
DefaultCommands="ExpandCollapse" Width="100%" EnableDrag="false"
    <ContentTemplate> 
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> 
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1"
            <telerik:RadListBox ID="FieldListBox" runat="server" Width="375" BorderStyle="None" AllowReorder="true" 
                SelectionMode="Single" AllowDelete="true" OnDeleted="FieldListBox_Deleted" AutoPostBackOnDelete="true"
                <ItemTemplate> 
                    <telerik:RadComboBox ID="FieldCombo" runat="server" EmptyMessage="Select a field" OnClientLoad="LoadFieldCombo" 
                        OnItemsRequested="FieldCombo_ItemsRequested" OnSelectedIndexChanged="FieldCombo_SelectedIndexChanged" /> 
                    <telerik:RadTextBox ID="FieldNameTextbox" runat="server" /> 
                </ItemTemplate> 
                <Items> 
                    <telerik:RadListBoxItem Value="1" /> 
                    <telerik:RadListBoxItem Value="2" /> 
                </Items> 
            </telerik:RadListBox> 
        </telerik:RadAjaxPanel> 
    </ContentTemplate> 
</telerik:RadDock> 

protected void FieldCombo_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e) 
    RadComboBox combo = (RadComboBox)sender; 
    combo.Items.Add(new RadComboBoxItem("Form_Type""1")); 
    combo.Items.Add(new RadComboBoxItem("Admit_Date""2")); 
    combo.Items.Add(new RadComboBoxItem("Admit_DX""3")); 
    combo.DataBind(); 
    Page.Form.Controls.Add(combo); 

I did try registering the controls in Page_Load when it is a postback, because I found that advice in an older post, and FieldCombo_ItemsRequested still isn't hit, but I don't get the errors.

This seems to be the only issue with updating to this version within our application, so I'm really hoping to find a resolution, since this version is supposed to fix a different bug that we were having problems with.

8 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 17 May 2010, 05:58 PM
Hi Misty Fowler,

Thank you for the working code.

I tested it with the latest Internal build and it worked properly. Can you please download the latest Internal build from your account and upgrade to verify whether it fixes the issue on your side?

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
Winston Yong
Top achievements
Rank 1
answered on 08 Sep 2010, 05:16 AM
Hi!
I am getting the same problem. I have download the latest version of telerik 2010.2.826.25 but its still giving this error.

kindly provide the solution for this.

Kind Regards
Chen, Winston

0
Simon
Telerik team
answered on 13 Sep 2010, 10:26 AM
Hello Winston Yong,

Could you reproduce the issue with the previous code as I was unable to do so? If not, please provide me code that reproduces the issue so that I can test the issue.

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
msigman
Top achievements
Rank 2
answered on 07 Nov 2010, 02:38 AM
Same issue with 2010.2.929.40, but mine is in the ItemTemplate of a RadMenu instead of ListBox.  Same error.

RadMenu code:
RadMenuItem one = new RadMenuItem();
one.ItemTemplate = new OneTemplate();
RadMenu1.Items.Add(one);

And the ComboBox code:
class OneTemplate : ITemplate
{
    public void InstantiateIn(Control container)
    {
        RadComboBox combo = new RadComboBox();
        combo.EmptyMessage = "Search";
        combo.Width = 250;
        combo.IsCaseSensitive = false;
     combo.OnClientSelectedIndexChanged = "Search";
        combo.DataTextField = "MenuItemName";
        combo.DataValueField = "MenuItemName";
        combo.DataSource = SecurityContext.GetMenu();
        combo.EnableAutomaticLoadOnDemand = true;
          
        container.Controls.Add(combo);
    }
    private void label1_DataBinding(object sender, EventArgs e)
    {
        Label target = (Label)sender;
        RadMenuItem item = (RadMenuItem)target.BindingContainer;
        string itemText = (string)DataBinder.Eval(item, "Text");
        target.Text = itemText;
    }
}
0
msigman
Top achievements
Rank 2
answered on 09 Nov 2010, 08:22 PM
The issue still remains.  It works fine if I remove it from the RadMenu. 

It also happens if I use EnableLoadOnDemand instead of EnableAutomaticLoadOnDemand.
0
Simon
Telerik team
answered on 11 Nov 2010, 03:51 PM
Hi msigman,

The reason for this error lies in the setup you are using. Here is what happens when you add the Item and instantiate its Template *on each* page load: RadComboBox has ViewState, so after postback it recreates its Items from the ViewState. Page_Load executes during callbacks as well, so when the RadComboBox initiates its Load On Demand request two things happen:
  • The first Item is recreated from the ViewState, however its child controls are not (this is a specific of the ASP.NET Framework).
  • In Page_Load you create another Item and instantiate another RadComboBox in it. Now the UniqueID of this RadComboBox is different - it contains "i1" as part of its ID indicating that it is in the second Item of its Container.
As the UniqueID of the RadComboBox initiating the callback request has "i0", the new RadComboBox control cannot be found, hence the error.

As a conclusion you must make sure the RadComboBox is added on each request *at the same* place. One way to achieve this in your case is to move the code from Page_Load to OnInit.

I hope this helps.

Kind regards,
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
msigman
Top achievements
Rank 2
answered on 11 Nov 2010, 04:21 PM
You were correct.  I was using if(!IsPostBack) to prevent this code from re-running, which meant on postback it wasn't recreating the entire control as I thought it would.  Moving to OnInit AND removing the if(!IsPostBack) fixed it.

In a final bit of irony, now it goes to the server with each keypress, which is actually not what I wanted (I just need it to load the list once, then stop).  So I think I'm going to keep the original method unless you know of a way to use LoadOnDemand without re-fetching the data on each keypress?  I believe that's actually the intended behavior for that control though.

Thanks again.
0
Simon
Telerik team
answered on 16 Nov 2010, 02:47 PM
Hello msigman,

Yes, Load On Demand is intended to work in this way - Items are loaded on each key press. However you can achieve your requirement with a bit of tweaking.

First you can set the ItemsPerRequest property to -1 to force the control to load all Items at once.

Then you can handle the client-side ItemsRequesting event in this way:
function onItemsRequesting(sender, eventArgs) {
    eventArgs.set_cancel(sender.get_items().get_count() > 0);
}

This code will stop each Items request which is initiated when there are Items in the drop down, i.e. it will allow only the first request.

I hope this helps.

Regards,
Simon
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
ComboBox
Asked by
WRONG ACCOUNT
Top achievements
Rank 1
Answers by
Simon
Telerik team
Winston Yong
Top achievements
Rank 1
msigman
Top achievements
Rank 2
Share this question
or