[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Mark Scott

1/4/2003 12:15:00 AM

I have for example a Web UserControl called Header, it has various
properties, but I currently have to call a function to add links to the
header. I have to in code say something like header.AddLink("Home",
"/index.html");

What I would like is to rather than have that function, be able to specify
this in the html part of the aspx page, something like:

<mycode:header runat="server" Property1="0" Property2="True">
<HeaderLink Text="Home Page" URL="/index.html" />
<HeaderLink Text="Software Section" URL="/software/index.html" />
</mycode:header>

In the code, I add special links into the header, and would like the html
example to be able to accomplish the same thing. However, I'm not sure
where I would even start on accomplishing having this HeaderLink subitem
setup. I have many other times desired this functionality in my web
controls, but went about it differently.

The code doesn't have to look exactly like what I typed above, but something
along those lines, such that I don't have to put some inline code to call my
'AddLink' function, either in the .aspx or in the .cs file. Doing something
similar to the method I desire would improve readability greatly.

Thanks in advance!

Mark E. Scott Jr.
mscott@awfs.net


1 Answer

Jesse Ezell

1/4/2003 9:33:00 PM

0

What you need to do is add the proper attributes and
properties to your class.

Do something like this:


[ParseChildren(true), PersistChildren(false)]
public class Header : WebControl, INamingContainer
{

// ...

HeaderItemCollection items = new HeaderItemCollection
();
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public HeaderItemCollection Items
{
get
{
return items;
}
}

//...
}

For a more complete description, check MSDN for
information about creating composite controls. They have
a ton of explaination and examples on this.

--Jesse