Problem dynamically loading a user control....

From: José Joye (jose.joye_at_KILLTHESPAMSbluewin.ch)
Date: 09/16/04


Date: Thu, 16 Sep 2004 07:53:43 +0200

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(Control control)
   System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter
writer)
   System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
writer)
   System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer)
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   System.Web.UI.Control.Render(HtmlTextWriter writer)
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
   System.Web.UI.Control.Render(HtmlTextWriter writer)
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
   System.Web.UI.Page.ProcessRequestMain()

Thanks,
José



Relevant Pages

  • asp to asp.net object type error
    ... The source code that generated this unhandled exception can only be ... application to be compiled in debug mode. ... System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ... includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) ...
    (microsoft.public.dotnet.framework)
  • asp to asp.net with block variable not set error
    ... An unhandled exception occurred during the execution of ... System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ... ControlAdapter adapter) +53 ... includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) ...
    (microsoft.public.dotnet.framework)
  • web part unexpected error in Photo Gallery page
    ... Exception Details: System.NullReferenceException: Object reference not ... The source code that generated this unhandled exception can only be ... application to be compiled in debug mode. ... System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243 ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: "A page can have only one server-side Form tag." when NONE exist!
    ... you do need a Form tag. ... > An unhandled exception was generated during the execution of the ... > the exception can be identified using the exception stack trace below. ... > System.Web.UI.Page.OnFormRender(HtmlTextWriter writer, String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: NET1.1: RangeValidator doesnt work with Hungarian DateTime
    ... The stack trace shows that the error is somewhere deep ... PLEEEASEE HEEEELP - anyone... ... Can it be converted to a valid date string? ... System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) ...
    (microsoft.public.dotnet.framework.aspnet)