Hello,
I'm playing around with dynamically loading user controls ...and having
problems
I created a really simple userControl (in fact contains a plain text box)
and placed it into the MyTestCtrl2.ascx file.
In an aspx file I placed the following in the Page_Load method:
private void Page_Load(object sender, System.EventArgs e)
{
Control uc2 = LoadControl("MyTestCtrl2.ascx");
Page.Controls.Add(uc2);
}
However, I'm always getting this error:
Control '_ctl0_TextBox1' of type 'TextBox' must be placed inside a form tag
with runat=server.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Control '_ctl0_TextBox1' of
type 'TextBox' must be placed inside a form tag with runat=server.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Control '_ctl0_TextBox1' of type 'TextBox' must
be placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Con trol control)
System.Web.UI.WebControls.TextBox.AddAttributesToR ender(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
writer)
System.Web.UI.WebControls.TextBox.Render(HtmlTextW riter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Page.ProcessRequestMain()
Thanks,
José