2010 Q1SP1 - OnItemsRequested Not Firing When In ListBox ItemTemplate

9 posts, 0 answers
  1. WRONG ACCOUNT
    WRONG ACCOUNT avatar
    8 posts
    Member since:
    Apr 2010

    Posted 11 May 2010 Link to this post

    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.
  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 17 May 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Winston Yong
    Winston Yong avatar
    13 posts
    Member since:
    Aug 2009

    Posted 08 Sep 2010 Link to this post

    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

  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 13 Sep 2010 Link to this post

    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
  6. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 06 Nov 2010 Link to this post

    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;
        }
    }
  7. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 09 Nov 2010 Link to this post

    The issue still remains.  It works fine if I remove it from the RadMenu. 

    It also happens if I use EnableLoadOnDemand instead of EnableAutomaticLoadOnDemand.
  8. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 11 Nov 2010 Link to this post

    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
  9. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 11 Nov 2010 Link to this post

    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.
  10. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 16 Nov 2010 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017