DropDownList in composite control not saving ListItems

S

Steve Trandahl

I have a composite control consisting of a DropdownList control and a button.
I've included an Items property that returns a reference to the
DropDownList's Items property, but when I add ListItems to it in Design mode,
they aren't added as <asp:ListItem> in the HTML tab. Instead
"Items=(Collection)" appears in the Control's tag and the designer eventually
"forgets" the ListItems that were entered.

How do I get the designer to add an asp:ListItem for each Item the way it
does with the standard DropDownList that's part of my control?

Thanks,
Steve
 
S

Steve Trandahl

I solved my problem by doing three more things:
1) using ParseChildrenAttribute(true, "Items") instead of
ParseChildrenAttribute(true) so it knew the information linked to the "Items"
property instead of an "asp:ListItem" property.
2) Made the Items property read only. When I didn't do that, I got a strange
error - '' could not be set on property "Items".
3) Executed this.EnsureChildControls() before attempting to read the Items
property of the DropDownList that was part of the composite control. This
caused the error "Items could not be initialized" which I assumed was a
parsing error, but wasn't. That became clear when I actually ran the project
and the debugger flagged that line with the error.

I hope this helps others who have these same problems. It's hard to find
information on this.

Steve
 

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

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top