Loadcontrol + formview = problems...

Discussion in 'ASP .Net' started by Jéjé, Oct 12, 2005.

  1. Jéjé

    Jéjé Guest


    I want to dynamically load an ASCX control which contain a formview.
    And I want to render the result into a string.

    but I receive some errors like:
    Control 'FormView1' of type 'FormView' must be placed inside a form tag with

    StringBuilder stringBuilder = new StringBuilder();

    StringWriter stringWriter;

    HtmlTextWriter htmlTextWriter;

    stringWriter = new StringWriter(stringBuilder);

    htmlTextWriter = new HtmlTextWriter(stringWriter);

    ctl = Page.LoadControl("~/controls/Overview.ascx");

    ..... some commands here ....



    return stringBuilder.ToString();

    what can I do?


    Jéjé, Oct 12, 2005
    1. Advertisements

  2. Jéjé

    Karl Seguin Guest

    This might work, not sure. Place the control on the page, call
    RenderControl() then remove it :)


    where somePlaceHolder is just an <asp:placeholder control inside a form.

    Karl Seguin, Oct 13, 2005
    1. Advertisements

  3. Jéjé

    Jéjé Guest

    allready tried, and this cause another error
    which is:
    The RegisterRequiresViewStateEncryption() method needs to be called before
    or during Page_PreRender.

    when I try to add the control in the placeholder.
    Jéjé, Oct 13, 2005
  4. Jéjé

    Jéjé Guest

    another try:

    during the oninit I add the control in the page, then I render this control
    only later, but in this case the error is:
    Control 'ctl00_MainContent_MyControl_FormView1' of type 'FormView' must be
    placed inside a form tag with runat=server.

    The rendering process of the formview verify that the control is correctly
    created in a page.

    Can I create a page in memory???
    Jéjé, Oct 13, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.