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

Dynamically created ComboBox and Load-on-demand not working

10 Answers 665 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
AndyB
Top achievements
Rank 1
AndyB asked on 18 Sep 2008, 03:02 PM
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

10 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 22 Sep 2008, 02:12 PM
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.
0
rvalencia
Top achievements
Rank 1
answered on 02 Oct 2008, 07:53 PM
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
0
Simon
Telerik team
answered on 07 Oct 2008, 12:05 PM
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.
0
Rajnikanth
Top achievements
Rank 1
answered on 09 Aug 2011, 07:41 AM
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.

0
Helen
Telerik team
answered on 12 Aug 2011, 09:47 AM
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.

0
Marian
Top achievements
Rank 1
answered on 09 Sep 2011, 10:01 AM
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!
0
George
Top achievements
Rank 1
answered on 12 Apr 2012, 10:58 PM
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.
0
Peter
Telerik team
answered on 16 Apr 2012, 01:28 PM
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.
0
Ted Power
Top achievements
Rank 1
answered on 12 Jun 2012, 08:38 PM
Has this issue been resolved?
0
Helen
Telerik team
answered on 13 Jun 2012, 09:04 AM
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.
Tags
ComboBox
Asked by
AndyB
Top achievements
Rank 1
Answers by
Simon
Telerik team
rvalencia
Top achievements
Rank 1
Rajnikanth
Top achievements
Rank 1
Helen
Telerik team
Marian
Top achievements
Rank 1
George
Top achievements
Rank 1
Peter
Telerik team
Ted Power
Top achievements
Rank 1
Share this question
or