NET HyperLink control and adds it to the TemplateMenu
control child controls:
private void CreateMenuItem(string title, string url,
string target, string imageurl)
{
HyperLink link = new HyperLink();
link.Text = title;
link.NavigateUrl = url;
link.ImageUrl = imageurl;
link.Target = target;
Controls.Add(link);
}
The SeparatorTemplate uses a different template container, the SeperatorTemplateContainer,
but otherwise, the code follows the lead of the FooterTemplate and HeaderTemplate templates.
What is unique in this piece of code is the addition of code to render a sensible separator via
LiteralControl should the user decide not to wire in a SeparatorTemplate value in the .aspx page.
When you build a server control that supports templates, it is recommended that you ensure
the control functions properly, or at least degrades gracefully, with a basic default template if
templates are not specified.
The full version of the TemplateMenu control is shown in Listing 6-1.
Listing 6-1. The TemplateMenu Control
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;
using ControlsBook2Lib.Ch11.Design;
namespace ControlsBook2Lib.
Pages:
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372