Board index » Web Programming » Problems dynamically adding controls to a page
|
Kireeti
|
Problems dynamically adding controls to a page
Web Programming306
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag with runat=server." So I saw a web page that added controls like so: foreach (object item in Page.Controls) { if (item.GetType() == typeof(HtmlForm)) { ((HtmlForm)item).Controls.Add(obj); break;}} Which works fine in a normal web page, but when I place my code in a Content Page, this doesn't work. Why do controls like Label and Image work ok when adding controls using Controls.Add, and others give the runat=server error? How do I get this to work when I add controls in a content page? Any explanations or reference web pages would be appreciated. -- Mark - |
