dynamically add control
-
hi all, I have create one ascx file,then i called my aspx form in Programmatically this is the code **Dim c1 As Control = LoadControl("Web.ascx") Page.Controls.Add(c1),**Problem is i want add linkbutton, Dim link As System.Web.UI.WebControls.LinkButton link = c1.FindControl("linkbutton") but error showing, this is the error Control '_ctl0_LinkButton1' of type 'LinkButton' must be placed inside a form tag with runat=server. cheers
-
hi all, I have create one ascx file,then i called my aspx form in Programmatically this is the code **Dim c1 As Control = LoadControl("Web.ascx") Page.Controls.Add(c1),**Problem is i want add linkbutton, Dim link As System.Web.UI.WebControls.LinkButton link = c1.FindControl("linkbutton") but error showing, this is the error Control '_ctl0_LinkButton1' of type 'LinkButton' must be placed inside a form tag with runat=server. cheers
When adding controls dinamically to a page, you should add them inside a placeholder control. This assures that your controls will render correctly. Sometimes when not adding the controls in the place holder they will work other times they won't. Just like in your case. So, add a place holder control in the page controls collection, then add your linkbutton inside the place holder. regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
-
hi all, I have create one ascx file,then i called my aspx form in Programmatically this is the code **Dim c1 As Control = LoadControl("Web.ascx") Page.Controls.Add(c1),**Problem is i want add linkbutton, Dim link As System.Web.UI.WebControls.LinkButton link = c1.FindControl("linkbutton") but error showing, this is the error Control '_ctl0_LinkButton1' of type 'LinkButton' must be placed inside a form tag with runat=server. cheers
Because you add the dynamic control to the Controls collection of the Page instance, so it is placed outside the form element which is a child of the parent Page. So like Mircea suggested, you simply place a container like PlaceHolder control onto the web page inside in the form element, and add the dynamic control to the container.