473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2416
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nikolaj | last post by:
I'm loading a user control using the method: uc = Page.LoadControl("../UC.ascx"); Afterwards I set some variables in uc. For instance uc.Count = 10; Count is the number of link buttons...
0
by: Neil Young | last post by:
Hello group, I'm referring to a "rather old thread" (April 21st 2005). Because I also ran into problems with ASP.NET 2.0 formview and DBNull, but found a way around, I would like to share my...
0
by: hammad.awan_nospam | last post by:
Hello, This problem is really frustrating to me. I have a FormView on my page where I do all of the binding programatically. In other words, I don't use a datasource control but I bind to the...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
5
by: Andreas | last post by:
Hello, I have the following problem: I want to add to my site (test.aspx) one (1) UserControl (customer.ascx) several times - dynamically with a placeholder. As well I want to hand off...
4
by: Rob | last post by:
Hey all, So.. a simple FormView/SqlDataSource to handle inserting records into a table. The table has a primary key that the user enters (eg DiscountCode). If the user enters a duplicate the...
2
by: Islamegy® | last post by:
I'm use FormView for editing a photo gallery... I add FileUpload control to upload images to the Gallery. I'm binding my Formview to objectdatasource i tried upload images onItemInserting &...
0
by: MRW | last post by:
For some strange reason, I'm having problems finding a GridView in a FormView. I keep getting the error: Object reference not set to an instance of an object. I have the code below, it's very...
0
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I read some msdn and other articles about how does databinding among DataSource controls and FormView / GridView controls works but I still don't fully understand to this blackbox. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.