Prev | Current Page 370 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

InnerDefaultProperty),NotifyParentProperty(true)]
public MenuItemDataCollection MenuItems
{
get
{
if (menuData == null)
{
menuData = new MenuItemDataCollection();
}
return menuData;
}
}
Permitting data entry in child tags has one trade-off: a lack of template support. ASP.NET
assumes that all the child tags go into the DefaultProperty collection, and it will not parse if it
sees templates. For controls as simple as TagDataMenu, this is a reasonable trade-off. More advanced
controls, such as the Repeater control we build in Chapter 7, will expose a property that allows
web developers to set the data source programmatically.
The slimmed-down CreateControlHierarchy method doesn??™t have to worry about template
building. We??™re able to reuse CreateMenuItem from the TemplateMenu control. For menu link
separation, we use the pipe character (|) as the separator this time around:
override protected void CreateChildControls()
{
Controls.Clear();
CreateControlHierarchy();
}
private void CreateControlHierarchy()
{
int count = menuData.Count;
for (int index = 0; index < count; index++)
{
MenuItemData itemdata = (MenuItemData) menuData[index];
CreateMenuItem(itemdata.Title, itemdata.Url,
itemdata.ImageUrl, itemdata.


Pages:
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382