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

Dynamic loaded user controls throwing "could not find panel" errors

1 Answer 87 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 15 Jun 2012, 05:39 AM
Hey Guys,
Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_cpPageBody_ctl00_cpPageBody_reImageResources_Uploader_4_imgMainImagePanel'. If it is being updated dynamically then it must be inside another UpdatePanel.' when calling method: [nsIDOMEventListener::handleEvent]

I know this one is well talked about, but I can't find a lead that fits our exact usage.

The scenario is this: I have a form which holds a resources control.  This control loads in dynamically a variable number of another control for uploading images.  It does this according to a set of resources defined on the object being edited in the parent form.
When the resources are already populated on this object being edited, the initial call (in page_init) to RenderEditor() works just fine.  However, RenderEditor() is also called by an AJAX event on yet another control in the form - the one which actually changes which resources exists on the object being edited in the main form.  When this control is updated, an event fires which tells the resources control to RenderEditor() - and get the new config, and get the new imageupload controls to add in.  The update triggers just fine.

However, when the ResourceEditor control tries to do its dynamic load - I get the above error.  it is strange because the very panel it is looking for is one of the dynamically loaded ones - i.e how can it not find something that it had to find in the first place to get its ID ?

I realise this sounds a little vague, so I will summarise and then attach the code from my Resources control:

Control in form dynamically loads in sub-controls according to a config.  On load version works fine.
Second control in form changes that config and notifies first control it needs to update.
AJAX update fires OK, update is attempted but error is then thrown.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ResourceEditor.ascx.cs" Inherits="ArtsHub.Controls.ResourceEditor" %>
<%@ Reference Control="~/shared/controls/images/ImageUploader.ascx" %>
<asp:PlaceHolder ID="phDynamicUploads" runat="server" />
<asp:Literal ID="litTest" runat="server" Text="initialised" />
 And the code behind:
public partial class ResourceEditor : System.Web.UI.UserControl
{
    public Globals.SectionIds Section { get; set; }
    public ResourceTypes ResourceType { get; set; }
 
    public void RefreshResources(TemplateChangedEventArgs e)
    {           
        //BLL.Emailing.Emailing.EmailBug("Got to Refresh Resources from viewstate" , e.Resources.Count.ToString());
        RenderEditor(e.Resources);
    }
 
    /// <summary>
    /// Main dynamic control load method - takes the list of resources as param
    /// </summary>
    public void RenderEditor(List<Resource> theseResources)
    {
        litTest.Text = string.Format("<h2>There were {0} Resources to load", theseResources.Count);
 
        foreach (Resource r in theseResources)
        {
            // Only process the filtered type from the control
            if (r.ResourceType == ResourceType)
            {
                ImageUploader thisUploader = (ImageUploader)Page.LoadControl("/shared/controls/images/ImageUploader.ascx");
                thisUploader.ID = "Uploader_" + r.ResourceId.ToString();
                thisUploader.SectionId = Section;
                thisUploader.Width = r.Width;
                thisUploader.Height = r.Height;
                thisUploader.ImageType = r.ImageType.Value;
                thisUploader.ImageURL = ImageFactory.GetListingImageURL((int)Section, Utilities.GetListingId, r.ImageType.Value); // Get Original Image for preview
 
                Label thisLabel = new Label();
                thisLabel.Text = r.Description;
 
                //BLL.Emailing.Emailing.EmailBug("Loading res " + r.ResourceId, "");
 
                phDynamicUploads.Controls.Add(thisLabel);
                phDynamicUploads.Controls.Add(thisUploader);
            }
        }
    }
}
 If anyone could shed some light on this I'd be most grateful.

Thanks

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 20 Jun 2012, 08:13 AM
Hi Simon,

Note that the presented error appears most commonly in case some specific controls are double ajaxified by using RadAjaxManager and RadAjaxPanel at the same time to update the same part of the page or for some reason nested UpdatePanels appear on the page. Could you please inspect your ajax settings and double check if such nested settings appear in the application?

All the best,
Maria Ilieva
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
Ajax
Asked by
Simon
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or