469,270 Members | 1,011 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Loadcontrol + formview = problems...

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.


Nov 19 '05 #1
3 2296
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jéjé" <willgart_A_@hotmail_A_.com> wrote in message
news:Ot**************@TK2MSFTNGP14.phx.gbl...
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.

Nov 19 '05 #2
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.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OV**************@TK2MSFTNGP12.phx.gbl...
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jéjé" <willgart_A_@hotmail_A_.com> wrote in message
news:Ot**************@TK2MSFTNGP14.phx.gbl...
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.


Nov 19 '05 #3
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é" <willgart_A_@hotmail_A_.com> wrote in message
news:ee****************@TK2MSFTNGP14.phx.gbl...
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.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OV**************@TK2MSFTNGP12.phx.gbl...
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jéjé" <willgart_A_@hotmail_A_.com> wrote in message
news:Ot**************@TK2MSFTNGP14.phx.gbl...
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.



Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Nikolaj | last post: by
reply views Thread by hammad.awan_nospam | last post: by
reply views Thread by Metal2You | last post: by
5 posts views Thread by Andreas | last post: by
2 posts views Thread by Islamegy® | last post: by
reply views Thread by MRW | last post: by
reply views Thread by =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.