Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Ralf Müller #1
Enumerating Controls Collection in Control.Render() causes System.InvalidOperationException - Why???
Hi all!
any ideas why this code...
protected override void Render(HtmlTextWriter writer) {
Table table;
TableRow row;
TableCell cell;
table = new Table();
foreach(ListElement e in Controls) {
row = new TableRow();
cell = new TableCell();
cell.Controls.Add(e);
row.Cells.Add(cell);
table.Rows.Add(row);
}
table.RenderControl(writer);
}
.... produces the following Exception in my ListElementCollection (Composite
Control):
"System.InvalidOperationException: Die Liste, an die der Enumerator gebunden
ist, wurde geändert. Ein Enumerator kann nur verwendet werden, wenn die
Liste nicht geändert wird."
Sorry - I got the german language version of Visual Studio. It says that the
List the Enumerator is bound to has been altered and that an Enumerator can
only be used when the List is not altered. - But WHY ON EARTH is my Controls
Collection altered while my Control is being rendered???
Greetings, Ralf
Ralf Müller Guest
-
Question about Controls collection, CreateChildControls and Render methods
Hi, Consider this code (simplified) example: public class Person : Microsoft.SharePoint.WebPartPages.WebPart { private ImageButton _action =... -
custom control (with collection) do not render at Design time
Hello, I built a custom control... Everithing is working fine... EXCEPT... ;-) When I first place the control on the webform at design time it... -
System.InvalidOperationException: ExecuteReader: Connection property has not been initialized
Hello, I dont understand whats going on with my DB2 connector. I used to have the code in a class that worked fine. But when I tried to use it in a... -
System.InvalidOperationException: The type myobject[] may not be used in this context.
I am trying to return a custom object from a web service, and get this very cryptic message. System.InvalidOperationException: There was an error... -
Adding a control to the DataGrid collection controls
Hi I have built a DataGrid custom adding a panel of selection automatically produced in base to the columns of the DataGrid The panel has... -
John Saunders #2
Re: Enumerating Controls Collection in Control.Render() causes System.InvalidOperationException - Why???
"Ralf Müller" <mueller@julitec.de> wrote in message
news:eRaCJMS3EHA.3120@TK2MSFTNGP12.phx.gbl...Aren't you modifying your Controls collection when you add e (a member of> Hi all!
>
> any ideas why this code...
>
> protected override void Render(HtmlTextWriter writer) {
> Table table;
> TableRow row;
> TableCell cell;
>
> table = new Table();
>
> foreach(ListElement e in Controls) {
> row = new TableRow();
> cell = new TableCell();
> cell.Controls.Add(e);
> row.Cells.Add(cell);
> table.Rows.Add(row);
> }
>
> table.RenderControl(writer);
> }
>
> ... produces the following Exception in my ListElementCollection
> (Composite
> Control):
>
> "System.InvalidOperationException: Die Liste, an die der Enumerator
> gebunden
> ist, wurde geändert. Ein Enumerator kann nur verwendet werden, wenn die
> Liste nicht geändert wird."
> Sorry - I got the german language version of Visual Studio. It says that
> the
> List the Enumerator is bound to has been altered and that an Enumerator
> can
> only be used when the List is not altered. - But WHY ON EARTH is my
> Controls
> Collection altered while my Control is being rendered???
the Controls collection) to the Controls collection of the cell. A control
may only be in a single Controls collection.
In a case like this, I have stored my sub-controls in a collection separate
from the Controls collection. I then enumerate my private collection for
rendering.
John Saunders
John Saunders Guest
-
Ralf Müller #3
Re: Enumerating Controls Collection in Control.Render() causes System.InvalidOperationException - Why???
Thank you John! Wow - that was a dumb mistake!
"John Saunders" <johnwsaundersiii at hotmail.com> schrieb im Newsbeitrag
news:e8YwYsV3EHA.3132@TK2MSFTNGP14.phx.gbl...separate> "Ralf Müller" <mueller@julitec.de> wrote in message
> news:eRaCJMS3EHA.3120@TK2MSFTNGP12.phx.gbl...>> > Hi all!
> >
> > any ideas why this code...
> >
> > protected override void Render(HtmlTextWriter writer) {
> > Table table;
> > TableRow row;
> > TableCell cell;
> >
> > table = new Table();
> >
> > foreach(ListElement e in Controls) {
> > row = new TableRow();
> > cell = new TableCell();
> > cell.Controls.Add(e);
> > row.Cells.Add(cell);
> > table.Rows.Add(row);
> > }
> >
> > table.RenderControl(writer);
> > }
> >
> > ... produces the following Exception in my ListElementCollection
> > (Composite
> > Control):
> >
> > "System.InvalidOperationException: Die Liste, an die der Enumerator
> > gebunden
> > ist, wurde geändert. Ein Enumerator kann nur verwendet werden, wenn die
> > Liste nicht geändert wird."
> > Sorry - I got the german language version of Visual Studio. It says that
> > the
> > List the Enumerator is bound to has been altered and that an Enumerator
> > can
> > only be used when the List is not altered. - But WHY ON EARTH is my
> > Controls
> > Collection altered while my Control is being rendered???
> Aren't you modifying your Controls collection when you add e (a member of
> the Controls collection) to the Controls collection of the cell. A control
> may only be in a single Controls collection.
>
> In a case like this, I have stored my sub-controls in a collection> from the Controls collection. I then enumerate my private collection for
> rendering.
>
> John Saunders
>
>
Ralf Müller Guest
-
John Saunders #4
Re: Enumerating Controls Collection in Control.Render() causes System.InvalidOperationException - Why???
"Ralf Müller" <mueller@julitec.de> wrote in message
news:u$5E$ud3EHA.2676@TK2MSFTNGP12.phx.gbl...Not really dumb. It's just that many .NET collections work this way. A> Thank you John! Wow - that was a dumb mistake!
DataRow can only be in one DataTable.Rows collection, for instance.
John Saunders
> "John Saunders" <johnwsaundersiii at hotmail.com> schrieb im Newsbeitrag
> news:e8YwYsV3EHA.3132@TK2MSFTNGP14.phx.gbl...> separate>> "Ralf Müller" <mueller@julitec.de> wrote in message
>> news:eRaCJMS3EHA.3120@TK2MSFTNGP12.phx.gbl...>>>> > Hi all!
>> >
>> > any ideas why this code...
>> >
>> > protected override void Render(HtmlTextWriter writer) {
>> > Table table;
>> > TableRow row;
>> > TableCell cell;
>> >
>> > table = new Table();
>> >
>> > foreach(ListElement e in Controls) {
>> > row = new TableRow();
>> > cell = new TableCell();
>> > cell.Controls.Add(e);
>> > row.Cells.Add(cell);
>> > table.Rows.Add(row);
>> > }
>> >
>> > table.RenderControl(writer);
>> > }
>> >
>> > ... produces the following Exception in my ListElementCollection
>> > (Composite
>> > Control):
>> >
>> > "System.InvalidOperationException: Die Liste, an die der Enumerator
>> > gebunden
>> > ist, wurde geändert. Ein Enumerator kann nur verwendet werden, wenn die
>> > Liste nicht geändert wird."
>> > Sorry - I got the german language version of Visual Studio. It says
>> > that
>> > the
>> > List the Enumerator is bound to has been altered and that an Enumerator
>> > can
>> > only be used when the List is not altered. - But WHY ON EARTH is my
>> > Controls
>> > Collection altered while my Control is being rendered???
>> Aren't you modifying your Controls collection when you add e (a member of
>> the Controls collection) to the Controls collection of the cell. A
>> control
>> may only be in a single Controls collection.
>>
>> In a case like this, I have stored my sub-controls in a collection>>> from the Controls collection. I then enumerate my private collection for
>> rendering.
>>
>> John Saunders
>>
>>
>
John Saunders Guest



Reply With Quote

