Loading Dynamic User Control Error: "The control must be placed inside a form tag with runat=server"

Discussion in 'ASP .Net' started by davidr@sharpesoft.com, Aug 31, 2006.

  1. Guest

    Hi,

    I have a panel that I load user Control in no problem. The problem
    arrises when I do a post back on one of these user controls. I have
    button it does a click event. In this click event I will do some
    database updates, then I will use reflection to call a method in the
    parent (this.page) to load the new user control. Its at this point
    after it loads the new user control that it throws the error "The
    control must be placed inside a form tag with runat=server".
    Now, my methods that managers the user control works. I am able to
    click on the parent page menu and load other user controls no problem.
    This only occurs when I'm trying to load a new user control in place of
    the current user control from the current child user control.

    So something like this:

    Parent page has method:

    public void PostBackLoadUserControl(string Description, string
    fileName)
    {
    LoadUserControl(fileName);

    }

    Current user control click event does this:

    protected void Button1_Click(object sender, EventArgs e)
    {
    //Session.Add("LoadUC", new string[] { "Test Control 4",
    "test4.ascx" });

    MethodInfo mi =
    this.Page.GetType().GetMethod("PostBackLoadUserControl",
    BindingFlags.Public | BindingFlags.Instance);
    if (mi != null)
    mi.Invoke(this.Page, new Object[] { "Test Control",
    "test.ascx"});

    }

    The mi.Invoke works and after it loads in the new user control it comes
    back to the Button1_Click event and leaves ok. After that the page
    tries to load with the new user control and throws the error "The
    control must be placed inside a form tag with runat=server".
    This control will be inside a form tag when its loaded because it is
    loaded into a panel that is inside a form tag. I'm not sure why this
    only happens when trying to do it from a child user control.

    Thank,

    David
     
    , Aug 31, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jo Inferis
    Replies:
    0
    Views:
    397
    Jo Inferis
    Jun 20, 2004
  2. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: Dynamic user control loading/initialising

    Phil Winstanley [Microsoft MVP ASP.NET], Jun 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    403
    Jo Inferis
    Jun 20, 2004
  3. =?Utf-8?B?UHJvZGlwIEsgU2FoYQ==?=

    Dynamic Loading of User Control with ViewState Preserved (Live Dem

    =?Utf-8?B?UHJvZGlwIEsgU2FoYQ==?=, Oct 28, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    5,714
    =?Utf-8?B?UHJvZGlwIEsgU2FoYQ==?=
    Oct 28, 2005
  4. =?Utf-8?B?U3JpZGhhcg==?=
    Replies:
    1
    Views:
    469
    =?Utf-8?B?RWx0b24gVw==?=
    Nov 18, 2005
  5. Prodip K Saha
    Replies:
    0
    Views:
    129
    Prodip K Saha
    Oct 28, 2005
Loading...

Share This Page