[Solved] How to add Dynamic controls to Content Page in ASP.Net

Last Reply on May 18, 2015 05:36 AM By Mudassar

Posted on May 18, 2015 05:35 AM

DEar Sir,

I have reffered your link http://www.aspsnippets.com/Red/Articles/Creating-Dynamic-DropDownList-Controls-in-ASP.Net.aspx.I need to add the dynamic dropdown on content page from content page itself,i have tried the below code its throwing error object instance property cannot be null.Please help me i have spent whole day on this..

        protected void Page_PreInit(object sender, EventArgs e)
              //Create a Dynamic Panel
              Panel pnlDropDownList; 
              pnlDropDownList = new Panel();
              pnlDropDownList.ID = "pnlDropDownList";
              pnlDropDownList.BorderWidth = 1;
              pnlDropDownList.Width = 300;
              ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.FindControl("ContentPlaceHolder1");
              Panel panel = (Panel)cph.FindControl("Panel1");