REPOST: Adding child elements to user control declaration

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Didn't get any response last time from a simliar question, but I know this
can be done...any insight would be greatly appreciated!!

________

I have a user control that exposes several public properties--for example,
CurrentColor. In Visual Studio, I
can access my custom properties using Intellisense just fine...

<ctl:MyDropDown id="ctl1" runat="server" CurrentColor="..." />

However, I cannot add inner HTML (in this case, ListItems) to the
declaration. How can I code my control to behave like a DropDownList
control, so I can do something like this?

<ctl:MyDropDown id="ctl1" runat="server" CurrentColor="...">
<asp:ListItem Text="..." Value="..." />
<asp:ListItem Text="..." Value="..." />
<asp:ListItem Text="..." Value="..." />
</ctl:MyDropDown>

Thank you,

newGuy
 
<ctl:MyDropDown id="ctl1" runat="server" CurrentColor="..." />

However, I cannot add inner HTML (in this case, ListItems) to the
declaration. How can I code my control to behave like a DropDownList
control, so I can do something like this?

Ensure that ParseChildren and PersistChildren attributes are applied to the
container control (MyDropDown).

From MSDN:
The PersistChildrenAttribute is used in combination with the
ParseChildrenAttribute to determine how nested content of a control is
interpreted. If PersistChildrenAttribute is true and ParseChildrenAttribute
is false, the nested content contained within an ASP.NET server control is
persisted as controls. If PersistChildrenAttribute is false and
ParseChildrenAttribute is true, the nested content is persisted as
properties of the server control.




--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
you need to create support for parsing your children. see ParseChildren
property.

-- bruce (sqlwork.com)
 
That is perfect, thank you very much Gaurav and Bruce.

If anyone is having this same problem, I did finally find an example on MSDN
that was very useful:

http://msdn2.microsoft.com/en-us/library/4s70936s(VS.80).aspx


MasterGaurav (www.edujini-labs.com) said:
<ctl:MyDropDown id="ctl1" runat="server" CurrentColor="..." />

However, I cannot add inner HTML (in this case, ListItems) to the
declaration. How can I code my control to behave like a DropDownList
control, so I can do something like this?

Ensure that ParseChildren and PersistChildren attributes are applied to the
container control (MyDropDown).

From MSDN:
The PersistChildrenAttribute is used in combination with the
ParseChildrenAttribute to determine how nested content of a control is
interpreted. If PersistChildrenAttribute is true and ParseChildrenAttribute
is false, the nested content contained within an ASP.NET server control is
persisted as controls. If PersistChildrenAttribute is false and
ParseChildrenAttribute is true, the nested content is persisted as
properties of the server control.




--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
 
Back
Top