Dynamic loading of Webusercontrol.....
-
Hi, I have created a Webusercontrol named sample.ascx. I Have to dynamically load the usercontrol in my Webform. The usercontrol has textbox control named Usernametxt,label control named UsernameLbl and a button control named Loginbtn The following is the code i used in the pageload of my Webform, protected void Page_Load(object sender, EventArgs e) { WebUserControl c; c = LoadControl("WebUserControl.ascx") as WebUserControl; if (c != null) { Controls.Add(c); } } I get the following error: Control 'ctl02_Usernametxt' of type 'TextBox' must be placed inside a form tag with runat=server. Can ne body help me fixing the bug
zari
-
Hi, I have created a Webusercontrol named sample.ascx. I Have to dynamically load the usercontrol in my Webform. The usercontrol has textbox control named Usernametxt,label control named UsernameLbl and a button control named Loginbtn The following is the code i used in the pageload of my Webform, protected void Page_Load(object sender, EventArgs e) { WebUserControl c; c = LoadControl("WebUserControl.ascx") as WebUserControl; if (c != null) { Controls.Add(c); } } I get the following error: Control 'ctl02_Usernametxt' of type 'TextBox' must be placed inside a form tag with runat=server. Can ne body help me fixing the bug
zari
Hi zari, the textbox (and all other input controls) must be embedded into a form. Only a form can post the user input to the server. You need something like that.I think, that you already have this form-Tag in your page. Just change the line "Controls.Add(c);" to "Form.Controls.Add(c);". Tom