Groups | Blog | Home
all groups > asp.net building controls > may 2004 >

asp.net building controls : AddParsedSubObject and LoadViewState


michaelacombs NO[at]SPAM hotmail.com
5/18/2004 3:14:24 PM
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,
Teemu Keiski
5/20/2004 11:30:21 AM
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.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


[quoted text, click to view]

Sergey Polyakov
5/24/2004 10:14:09 AM
Hi Teemu,

[quoted text, click to view]

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

Sergey

[quoted text, click to view]

Sergey Polyakov
5/24/2004 10:17:55 AM
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

[quoted text, click to view]

Teemu Keiski
5/25/2004 10:11:39 PM
Yeah, that is true. I just didn't get that impression. ;-)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


[quoted text, click to view]

AddThis Social Bookmark Button