Loadcontrol + formview = problems...

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

  1. Jéjé

    Jéjé Guest

    Hi,

    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
    runat=server


    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 ....

    ctl.DataBind();

    ctl.RenderControl(htmlTextWriter);

    return stringBuilder.ToString();



    what can I do?



    thanks.



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

  2. Jéjé

    Karl Seguin Guest

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

    somePlaceHolder.Controls.Add(ctl);
    ctl.DataBind();
    ctl.RenderControl(htmlTExtWriter);
    somePlaceHolder.Controls.Remove(ctl);


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

    Karl
     
    Karl Seguin, Oct 13, 2005
    #2
    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
    #3
  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
    #4
    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.