Dynamic ASP.NET controls using Infragistics

Posted by Emil D on Stack Overflow See other posts from Stack Overflow or by Emil D
Published on 2010-04-19T18:22:04Z Indexed on 2010/04/19 18:33 UTC
Read the original article Hit count: 650

Filed under:
|
|
|

So, in my asp.net webapp I need to dynamically load a custom control, based on the selected value of a dropdown list.That seems to work at first glance, but for some reason all infragistics controls that I have in my custom control appear, but won't work.I get a "Can't init [controlname]" warning in my browser.If I declare my custom control statically, this problem doesn't apprear Here's my code:

Markup:

<%@ Control Language="C#" 
            AutoEventWireup="true" 
            CodeBehind="GenericReportGUI.ascx.cs" 
            Inherits="GenericReportGUI" %>

<%@ Register assembly="Infragistics35.WebUI.Misc.v8.3, Version=8.3.20083.1009,Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" 
             namespace="Infragistics.WebUI.Misc" 
             tagprefix="igmisc" %>

<asp:UpdatePanel ID="myUpdatePanel"
                 runat="server"
                 UpdateMode="Conditional">
<ContentTemplate>
    <igmisc:WebPanel ID="WebPanel1" 
                     runat="server">
        <Template>  
            <div>      
            <asp:PlaceHolder ID="Placeholder" 
                             runat="server">
            </asp:PlaceHolder>

            </div>
        </Template>                 
    </igmisc:WebPanel>
</ContentTemplate>                 
</asp:UpdatePanel>

Code-behind:

public partial class GenericReportGUI : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected override void OnPreRender( EventArgs e )
    {
        base.OnPreRender(e);
        loadCustomControl();
    }

    protected void loadCustomControl()
    {
        Placeholder.Controls.Clear();

        string controlPath = getPath(); //getPath() returns the path to the .ascx file we need to load, based on the selected value of a dropdownlist


        try 
        {
            Control newControl = LoadControl( controlPath );
            Placeholder.Controls.Add( newControl );
        }
        catch
        {
            //if the desired control cannot be loaded, display nothing
        }

        myUpdatePanel.Update();//Update the UpdatePanel that contains the custom control
    }
}

I'm a total noob when it comes to asp.net, so any help with this issue would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET