MenuItem

Answered (Verified) This post has 1 verified answer and 3 replies

Not Ranked
Posts: 4
taborro Posted: Wed Dec 30, 2009 @ 3:29 PM
Hi,

I'm trying to use the "Dynamic Content Menu" example for my own evil purposes:

C:\Program Files\ComponentArt\UI Framework 2009.3 for .NET\live_demos\aspnetajax\control-specific\menu\programming_server\dynamic_menuContent\

The interesting part of the example does this:

    ComponentArt.Web.UI.MenuItem dateTimeItem = Menu1.FindItemById("i_DateTime");
    ComponentArt.Web.UI.MenuItem newItem; 

    // Add day item 
    newItem = new ComponentArt.Web.UI.MenuItem(); 
    newItem.Text = DateTime.Now.DayOfWeek.ToString(); 
    dateTimeItem.Items.Add(newItem); 

Cool, just what I wanted ... BUT I want to style it up a bit, too.  So as I'm building my menu item's code, I'm adding some <ul>'s and some </li>'s like so:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
var rollHistory = DC.GetRecentRollHistory();
sb.Append("<ul>");
foreach (var roll in rollHistory)
{
    sb.Append("<li>");
    sb.Append(roll.RollDateTime.ToShortTimeString());
    sb.Append(" - ");
    sb.Append(roll.RollValue.ToString());
    sb.Append("</li>");
}
sb.Append("</ul>");

ComponentArt.Web.UI.MenuItem statsItem = Menu1.FindItemById("Stats");
ComponentArt.Web.UI.MenuItem newItem;

// Add day item 
newItem = new ComponentArt.Web.UI.MenuItem();

newItem.Text = Server.HtmlEncode(sb.ToString());
statsItem.Items.Add(newItem); 

But when it's output to the menu, it spits out a literal version of the string text I'm appending together ... in other words, the HTML is not rendered as HTML, just as text. 

So, you can see near the bottom of that example where I tried to do a Server.HtmlEncode ... I tried a few other ideas, but to no avail!

Here's what the problem looks like:



Help?!

BTW, I did see a previous thread in the Menu forums related to this, but the resolution (1) didn't really fit my situation, and (2) I'd like to hear what ComponentArt has to say about it.

Thanks!
Bob

Answered (Verified) Verified Answer

Top 10 Contributor
Posts: 6,014
Answered (Verified) stephen Posted: Thu Dec 31, 2009 @ 5:32 AM
Verified by taborro

You should use templates if you need to override our default rendering with custom markup- if it's just html (no server controls) you're after, you can use client templates. Here's a quick example loosely based on the above:

 

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<ul>");
        sb.Append("<li>steve</li>");
        sb.Append("<li>hatcher</li>");
        sb.Append("</ul>");

        ClientTemplate template = new ClientTemplate();
        template.Text = sb.ToString();
        template.ID = "myTemplate";
        Menu1.ClientTemplates.Add(template);

        ComponentArt.Web.UI.MenuItem parent = Menu1.FindItemById("p1");
        ComponentArt.Web.UI.MenuItem newItem = new ComponentArt.Web.UI.MenuItem();
        newItem.ClientTemplateId = "myTemplate";

        parent.Items.Add(newItem); 
I hope this helps.

Stephen Hatcher, Developer Support Manager

All Replies

Top 10 Contributor
Posts: 6,014
Answered (Verified) stephen Posted: Thu Dec 31, 2009 @ 5:32 AM
Verified by taborro

You should use templates if you need to override our default rendering with custom markup- if it's just html (no server controls) you're after, you can use client templates. Here's a quick example loosely based on the above:

 

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<ul>");
        sb.Append("<li>steve</li>");
        sb.Append("<li>hatcher</li>");
        sb.Append("</ul>");

        ClientTemplate template = new ClientTemplate();
        template.Text = sb.ToString();
        template.ID = "myTemplate";
        Menu1.ClientTemplates.Add(template);

        ComponentArt.Web.UI.MenuItem parent = Menu1.FindItemById("p1");
        ComponentArt.Web.UI.MenuItem newItem = new ComponentArt.Web.UI.MenuItem();
        newItem.ClientTemplateId = "myTemplate";

        parent.Items.Add(newItem); 
I hope this helps.

Stephen Hatcher, Developer Support Manager
Not Ranked
Posts: 4
taborro Posted: Thu Dec 31, 2009 @ 1:51 PM
Spot on, ol' chap.  You're a scholar and a gentleman!  :)
Thank you,
Bob
Top 10 Contributor
Posts: 6,014
stephen Posted: Mon Jan 4, 2010 @ 5:43 AM

Now that's a nice way to start a new year! Glad to have helped.

Stephen Hatcher, Developer Support Manager
Page 1 of 1 (4 items)