Loadcontrol + formview = problems...

J

Jéjé

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

Karl Seguin

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
 
J

Jéjé

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éjé

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

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. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top