Loading UserControl Dynamically in UpdatePanel

http://geekswithblogs.net/rashid/archive/2007/08/11/Loading-UserControl-Dynamically-in-UpdatePanel.aspx

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<asp:UpdatePanel ID="pnl1" runat="server">
    <ContentTemplate>
        <asp:PlaceHolder ID="plh1" runat="server"></asp:PlaceHolder>
    </ContentTemplate>
</asp:UpdatePanel>

private string LastLoadedControl
        {
            get
            {
                return ViewState["LastLoaded"] as string;
            }
            set
            {
                ViewState["LastLoaded"] = value;
            }
        }

        private void LoadUserControl()
        {
            string controlPath = LastLoadedControl;

            if (!string.IsNullOrEmpty(controlPath))
            {
                plh1.Controls.Clear();
                UserControl uc = (UserControl)LoadControl(controlPath);
                plh1.Controls.Add(uc);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            DotNetNuke.Framework.AJAX.RegisterScriptManager();

            string controlPath = string.Empty;

            if (Settings.ContainsKey("ddl1"))
                controlPath = Settings["ddl1"] + ".ascx";
            else
                controlPath = "Expired.ascx";

            LastLoadedControl = controlPath;
            LoadUserControl();
        }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s