Search:
Namespaces
Discussions
.NET v1.1
Feedback
Dynamic Controls and ViewState
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngarchitecture' list
.
Rob Morhaime
Hi all,
Having some trouble understanding the documentation here:
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskAddingControlsToW=
ebFormsPageProgrammatically.asp
Specifically, the warnings about inserting dynamic controls _between_ =
existing controls:
"If you insert dynamic controls _between_ existing controls, the dynamic =
control's view state information is inserted into the corresponding =
location of the view state structure. When the page is posted and the =
view state is loaded, the dynamic control does not yet exist; therefore, =
the extra information in view state does not correspond to the right =
control. The result is usually an error indicating an invalid cast."
I must ask myself, BETWEEN HOW?? Vertically on the page between? Left =
to right between? That don't make sense...
There's more: Why should the order of viewstate's contents matter? MS =
says the data stored in the viewstate collection is in a dictionary =
collection, so during INIT the values should be retrieved by name from =
the statebag.
thanks for any clarity,
Rob
Reply to this message...
Tom Cabanski
In my experience, you can only add dynamic controls beneath existing
static controls. As best I can tell, viewstate for controls is
positional and has nothing to do with the ID of the control. For
example, I've run into a situation where replacing a drop down list box
with an edit box, even with a different ID, causes a casting violation
at runtime when .NET tries to bring back the view state.
If you need to dynamically create controls in the visible middle
(reading left to right and top to bottom) and you use view state you
will run into trouble.
I'm sure there is some definitive information out there; I just have not
found it yet. The above is based on the painful experience of the
development team at my company.
Thanks
--------------------------------
Tom Cabanski, President
Objective Advantage, Inc.
http://www.oai.cc
Author of .NET Security coming soon from Manning
-----Original Message-----
From: Rob Morhaime [mailto:
Click here to reveal e-mail address
]
Sent: Friday, June 07, 2002 4:46 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Dynamic Controls and ViewState
Hi all,
Having some trouble understanding the documentation here:
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskAddingControlsTo
WebFormsPageProgrammatically.asp
Specifically, the warnings about inserting dynamic controls _between_
existing controls:
"If you insert dynamic controls _between_ existing controls, the dynamic
control's view state information is inserted into the corresponding
location of the view state structure. When the page is posted and the
view state is loaded, the dynamic control does not yet exist; therefore,
the extra information in view state does not correspond to the right
control. The result is usually an error indicating an invalid cast."
I must ask myself, BETWEEN HOW?? Vertically on the page between? Left
to right between? That don't make sense...
There's more: Why should the order of viewstate's contents matter? MS
says the data stored in the viewstate collection is in a dictionary
collection, so during INIT the values should be retrieved by name from
the statebag.
thanks for any clarity,
Rob
| [aspngarchitecture] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngarchitecture.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SE
Reply to this message...
mail
it refers to controls when you treat them in code not in the html
designer.
because all controls derive from System.Web.UI.WebControl even page
derives from it. All of them have have the Controls collection with all
of their childs. For example if you have a page with only a table as a
control you can reference that table as this.Controls[0] if you decide
to dinamically insert that table in another table you could load a table
control dinamically remove the table from the page.Controls collection
set the new table parent to the page (myNewTable.Parent = this.Page) and
then assign this table as parent of the old one myOldTable.Parent =
this.Controls[0]. I never tried the sintax may be wrong I'm trying to
illustrate the situation only.
-----Original Message-----
From: "Rob Morhaime" <
Click here to reveal e-mail address
>
To: "aspngarchitecture" <
Click here to reveal e-mail address
>
Date: Thu, 6 Jun 2002 14:45:48 -0700
Subject: [aspngarchitecture] Dynamic Controls and ViewState
[Original message clipped]
Reply to this message...
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com