Rob Cameron and Dale Michalk
"Pro ASP.NET 3.5 Server Controls and AJAX Components"
ImageUrl, itemdata.Target);
if ((count > 1) && (index < count - 1))
{
Controls.Add(new LiteralControl(" | "));
}
}
}
override protected void CreateChildControls()
{
CreateControlHierarchy();
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
}
}
Listing 6-8. The MenuControlBuilder Control Builder Class File
using System;
using System.Web;
using System.Web.UI;
using System.Collections;
namespace ControlsBook2Lib.Ch06
{
public class MenuControlBuilder : ControlBuilder
{
public override Type GetChildControlType(String tagName,
IDictionary attributes)
{
278 CHAPTER 6 ?– SERVER CONTROL TEMPLATES
if (String.Compare(tagName, "data", true) == 0)
{
return typeof(MenuItemData);
}
return null;
}
public override void AppendLiteralString(string s)
{
s.Trim();
// Ignores literals between tags.
}
}
}
Viewing the Tag Parsing Menu Controls
The Tag Parsing Menu web form demonstrates both of our declaratively loaded menu controls
in action. In Visual Studio, if you click the TagDataMenu control and select the MenuItems property,
you will see a button that, if clicked, will bring up a UI collection editor for the MenuItemData
collection. For the TagDataMenu control, the child tags take the name of the MenuItemData hyperlink
data class: