Groups | Blog | Home
all groups > asp.net building controls > july 2005 >

asp.net building controls : Web Form Designer deleting collection markup on Custom Server Control



Ken Baltrinic
7/6/2005 2:01:15 PM
I am trying to implement a custom server control which exposes a collection
and uses the ParseChildrenAttribute to populate it from child elements of
the controls aspx markup. In fact I am simply starting with Microsoft's
"ParseChildrenAttribute Sample". I have made no changes to this sample and
am having the following problem. If I change any property (Visible for
instance) of the custom control (CollectionPopertyControl in the case of the
sample) using the Properties Window of the Web Form Designer, the aspx
markup for the collection is deleted as follows:

What was orriginally:

<Custom:CollectionPropertyControl Header = "Employees" id = "prop" runat =
"server">
<Custom:Employee Name = "Alice" Alias = "AliceA" Title = "Manager" />
<Custom:Employee Name = "Jerry" Alias = "JerryR" Title = "Programmer" />
<Custom:Employee Name = "Lynn" Alias = "LynnP" Title = "Architect" />
<Custom:Employee Name = "Mike" Alias = "MikeB" Title = "Tester" />
</Custom:CollectionPropertyControl>

becomes:
<Custom:CollectionPropertyControl Header="Employees" id="prop"
runat="server" Visible="False"></Custom:CollectionPropertyControl>

How do I stop this from happening? I don't really need the collection to be
editable from the web for designer. I am happy to maintain the values by
editing the markup, BUT I do need the markup to survive the control's basic
properties being manipulated by the designer. I have tried seting the
collection property's Browsable attribute to false but that did not solve
the problem.

Suggestions?

Ken Dopierala Jr.
7/9/2005 11:00:41 PM
Hi Ken.

Check out the aspnet.buildingcontrols newsgroup for a lot of posts regarding
this stuff. More than likely you need to add this attribute to the property
of the custom control that holds the collection:

PersistenceMode(PersistenceMode.InnerDefaultProperty)

That alone may do it. If not check out the aforementioned Microsoft
newsgroup for a lot more information about controls. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

[quoted text, click to view]

Ken Dopierala Jr.
7/10/2005 6:36:55 AM
Hi,

Just realized this is the buildingcontrols group. Check out PersistenceMode
and overriding the function GetPersistInnerHtml(). Ken.

[quoted text, click to view]

AddThis Social Bookmark Button