Public partial class Site_DynamicPage : System.Web.UI.Page { private static Control uc; private static string lastControl = null; private void loadDynamically() { if (lastControl != null) { PlaceHolder1.Controls.Clear(); uc = Page.LoadControl("~/Site/Controls/" + lastControl + ".ascx"); PlaceHolder1.Controls.Add(uc); } } protected void Page_Load(object sender, EventArgs e) { loadDynamically(); } protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { lastControl = ListBox1.SelectedValue; loadDynamically(); } }
Quote:Controls are typically added to the page during the page's initialization stage. For details about page stages, see ASP.NET Page Life Cycle Overview.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)