Dynamically created ComboBox and Load-on-demand not working

11 posts, 0 answers
  1. AndyB
    AndyB avatar
    1 posts
    Member since:
    Feb 2006

    Posted 18 Sep 2008 Link to this post

    I am working on an  page that dymically creates controls at runtime as determined by a database definition.  This is an indexing application and the number and types of controls varies by document type.  Everything is working fine except the RadCombo box.  Because some of the value lists will be very long I am using the load on demand feature.  When I was testing this functionality I used the load on demand example with a design-time placed combox box and it worked great.  Now I am trying to duplicate this configuratiion with run time code and I'm getting the following error when I attempt to load the items on demand: 

    "The target '<my dynamic control id>' for the callback could not be found or did not implement ICallBackEventHandler."

    Here is my server side code used to create the combo box:

    object iControl =

    new RadComboBox();
    ((
    RadComboBox)iControl).Width = Unit.Pixel(200);
    ((
    RadComboBox)iControl).AllowCustomText = true;
    ((
    RadComboBox)iControl).ShowToggleImage = true;
    ((
    RadComboBox)iControl).ShowMoreResultsBox = true;
    ((
    RadComboBox)iControl).EnableLoadOnDemand = true;
    ((
    RadComboBox)iControl).EnableVirtualScrolling = true;
    ((
    RadComboBox)iControl).MarkFirstMatch = true;
    ((
    RadComboBox)iControl).ItemsRequested += new RadComboBoxItemsRequestedEventHandler(index_create_ItemsRequested);
    ((RadComboBox)iControl).ID = "~~~" + docFieldDef.FieldTypeName + "~~~fld~" + docFieldDef.FieldDefID.ToString();
    tbCell3.Controls.Add((RadComboBox)iControl);

    And here is the shell for he event handler, although this code does not get executed at present.

    protected void index_create_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
    {
    <snip>
    }

    Please let me know if I have missed something.
    Thanks,
    Andy

  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 22 Sep 2008 Link to this post

    Hi AndyB,

    Please make sure the the ComboBox is added to the Page Form's controls collection each time the page is submitted to the server - always and not only the first time or on postback.

    Regards,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. rvalencia
    rvalencia avatar
    1 posts
    Member since:
    Feb 2007

    Posted 02 Oct 2008 Link to this post

    Hi!!
    I have the same problem, but I don't understand as dynamically create a RadComboBox and add this control to the Page Form's controls collection each time the page is submitted to the server. Please, can you get me a answer with more details.

    Thanks,
    Rene
  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 07 Oct 2008 Link to this post

    Hello rvalencia,

    You need to make sure that the control is added to the Form's control collection on each postback.

    Ideally this should happen when the Page loads (Page_Load) on the server, outside of the "if (!Page.IsPostBack)" block (if any).

    You also need to ensure that the control is added at the same place each time.

    If you still experience the issue, please post here a portion of your code, which adds the control, so that I can examine it and hopefully provide the solution.

    All the best,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Rajnikanth
    Rajnikanth avatar
    2 posts
    Member since:
    Feb 2011

    Posted 09 Aug 2011 Link to this post

    Hi Simon , In my case i am adding the Radcombo boxes programmatically to a itemtemplate inside a gridview conditionally on griview onrowcreated event. but i am facing the same issue
    ("The target '<my dynamic control id>' for the callback could not be found or did not implement ICallBackEventHandler.")

    Here is the code snippet.
    protected void grdStagingReturns_RowCreated(object sender, GridViewRowEventArgs e)
           {
               if (e.Row.DataItem != null)
               {
                   if (e.Row.RowType == DataControlRowType.Header)
                   {
                       int sortColumnIndex = GetSortColumnIndex();
                       if (sortColumnIndex != -1)
                       {
                           AddSortImage(sortColumnIndex, e.Row);
                       }
                   }
                   if (e.Row.RowType == DataControlRowType.DataRow)
                   {
                       if (((StagingReturn)e.Row.DataItem).DiscoveryResult != null)
                       {
                           if (((StagingReturn)e.Row.DataItem).DiscoveryResult.DiscoveredEntity != null)
                           {
                               e.Row.Cells[3].Text = ((StagingReturn)e.Row.DataItem).DiscoveryResult.DiscoveredEntity.EntityName;
                           }
                           RadComboBox entityCombo = new Telerik.Web.UI.RadComboBox();
                           entityCombo.DataTextField = "EnittyName";
                           entityCombo.DataValueField = "EntityID";
                           entityCombo.DataSourceID = this.odsEntityDataSource.ID;
                           entityCombo.ItemsPerRequest = 10;
                           entityCombo.ShowMoreResultsBox = true;
                           entityCombo.EnableLoadOnDemand = true;
                           entityCombo.AllowCustomText = true;
                           e.Row.Cells[4].Controls.Add(entityCombo);
                       }
                   }
               }
           }


     Please let me know if i am missing any thing or do i have to re add the controls to the page on Callback if yes how can i achieve that?

    Thanks,
    Rajani.

  7. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 12 Aug 2011 Link to this post

    Hi Rajnikanth,

    Could you please open a support ticket and send us a sample project which demonstrates the issue to examine it locally?

    Regards,
    Helen
    the Telerik team

    Browse the vast support resources we have to jump start 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.

  8. Marian
    Marian avatar
    1 posts
    Member since:
    Sep 2011

    Posted 09 Sep 2011 Link to this post

    Hi, same problem here!

    I have a dynamic RadComboBox (with autocomplete and LoadOnDemand enabled) created on the InstantiateIn method, in the edit mode of an RadGrid. I'm using an IBindableTemplate interface to construct the edit form. 
    The control renders in page but when I begin to edit its value, it throws the same error.

    Note: Everything works ok when de Grid is in Display mode (also with ITemplate interface and the control enabled)  but when I switch an Grid item into Edit mode the RadComboBox throws the error.

    Thanks!
  9. George
    George avatar
    9 posts
    Member since:
    Apr 2011

    Posted 12 Apr 2012 Link to this post

    I am having the same issue reported above. I have a radcombobox control with enableloadondemand= true, itemsperrequest= 20, showmoreresultsbox = true properties set.
    After I add dynamically a new instance of the control on a button click event, when I edit / start typing in the radcombo box, i get this error.
    Please let me know how to fix this issue.
  10. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 16 Apr 2012 Link to this post

    Hello guys,

    We will need some more time to fully test the case. As soon as we are ready we will post our findings.

    Thank you for your patience and understanding.

    All the best,
    Peter
    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.
  11. Ted Power
    Ted Power avatar
    1 posts
    Member since:
    Jun 2012

    Posted 12 Jun 2012 Link to this post

    Has this issue been resolved?
  12. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 13 Jun 2012 Link to this post

    Hi George,

    In your case you have to add RadComboBox on every  Page_Load event like the following:

    protected void Page_Load(object sender, EventArgs e)
        {
            RadComboBox combo = new RadComboBox();
            combo.EnableLoadOnDemand = true;
            combo.ItemsPerRequest = 20;
            combo.ShowMoreResultsBox = true;
            combo.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(combo_ItemsRequested);
     
            Panel1.Controls.Add(combo);
        }
     
        protected void combo_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
             
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
             
        }

    If it doesn't help - could you please open a support ticket and send us your code to examine it locally?

    Actually the solution here depends on the specific case. In general, as Simon previously said,  you need to make sure that the control is added to the Form's control collection on each postback.

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