AddParsedSubObject and LoadViewState

M

Michael Combs

I am building a combobox webcontrol which works from a collection of
ListItems similar to a standard DropDownList. It uses
AddparsedSubObject to load the nested ListItem objects (below).

<cc1:combobox id="ComboBox1" runat="server">
<cc1:ListItem Text="test1" Value="1"
Selected="False"></cc1:ListItem>
<cc1:ListItem Text="test2" Value="2"
Selected="False"></cc1:ListItem>
</cc1:combobox>

I am also overriding Load and Save viewstate to maintain the listitems
in the viewstate. AddParsedSubObject is always called, in which the
nested ListItems are loaded into my item list. Then in LoadViewState,
I'm clearing my item list and loading the list items from the
viewstate. Is this the correct method for handling this situation?

Thanks,
Michael Combs
 
T

Teemu Keiski

Hi,

wouldn't it be easier to map the ListItems to the Items property (as it
happens with DDL), when you wouldn't need to deal with AddParsedSubObject as
this mapping happens automatically when control has ParseChildren(true),
PersistChildren(false) attributes applied (that is, it inherits from
WebControl). These attributes have impact that content between control's
tags need to map to the property or properties of the control.

DropDownList has Items property declared with
PersistenceMode(PersistenceMode.InnerDefaultProperty) so that all items
between begin and end tag must map to the Items property.

And about ViewState, if you add these ListItems to the Items on every
request (as happens with AddParsedSubObject), adding them to the ViewState
is overhead.
 
S

Sergey Polyakov

Hi Teemu,
And about ViewState, if you add these ListItems to the Items on every
request (as happens with AddParsedSubObject), adding them to the ViewState
is overhead.

It's not overhead if you want to change the item collection dynamically at
run-time.

Sergey
 
S

Sergey Polyakov

Hello Michael,

If the approach suggested by Teemu Keiski is not appropriate for some
reason, the way you handling the item list is quite correct

Sergey
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top