REPOST: Adding child elements to user control declaration

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
 
M

MasterGaurav \(www.edujini-labs.com\)

<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
-----------------------------------------
 
B

bruce barker

you need to create support for parsing your children. see ParseChildren
property.

-- bruce (sqlwork.com)
 
G

Guest

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
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top