E
ErwinP
Hello,
I'm having a bit of a problem with the ASP.NET Menu Web Control when
using a Dynamic Item Template. The template works fine for Menu Items
which are added using declarative persistence (Example 1). However
Menu Items which I add programmatically (Example 2) initially do not
receive the templated controls.
They are being displayed as 'ordinary' Menu Items until the next
PostBack when the template kicks in.
I've used Reflector to get a better understanding of how templates are
handled inside the Menu control and and my first impression is that
the Menu Control doesn't properly support templates for
programmatically added Menu Items. But as said; that's my first
impression so I really hope someone will prove me wrong!
Best regards,
Erwin
Example 1:
<asp:Menu runat="server" ID="PlaybackControl"
Orientation="Horizontal"
OnMenuItemClick="PlaybackControl_MenuItemClick">
<DynamicItemTemplate>
<asp:Label runat="server" ID="MenuText"><%# Eval("Text") %></
asp:Label>
<br />
<asp:Label runat="server" ID="MenuDesc"><%# Eval("ToolTip") %></
asp:Label>
</DynamicItemTemplate>
<Items>
<asp:MenuItem Text="Playback control">
<asp:MenuItem Text="Play" ToolTip="Start playback" />
<asp:MenuItem Text="Pause" ToolTip="Pause playback" />
<asp:MenuItem Text="Stop" ToolTip="Stop playback" />
</asp:MenuItem>
</Items>
</asp:Menu>
<br />
<asp:Button runat="server" ID="AddItem" Text="Add item"
OnClick="AddItem_Click" />
Example 2:
private void AddItem_Click(object sender, EventArgs e)
{
MenuItem newItem = new MenuItem();
newItem.Text = "New item";
newItem.ToolTip = "Newly added dynamic menu item";
PlaybackControl.Items[0].ChildItems.Add(newItem);
}
I'm having a bit of a problem with the ASP.NET Menu Web Control when
using a Dynamic Item Template. The template works fine for Menu Items
which are added using declarative persistence (Example 1). However
Menu Items which I add programmatically (Example 2) initially do not
receive the templated controls.
They are being displayed as 'ordinary' Menu Items until the next
PostBack when the template kicks in.
I've used Reflector to get a better understanding of how templates are
handled inside the Menu control and and my first impression is that
the Menu Control doesn't properly support templates for
programmatically added Menu Items. But as said; that's my first
impression so I really hope someone will prove me wrong!
Best regards,
Erwin
Example 1:
<asp:Menu runat="server" ID="PlaybackControl"
Orientation="Horizontal"
OnMenuItemClick="PlaybackControl_MenuItemClick">
<DynamicItemTemplate>
<asp:Label runat="server" ID="MenuText"><%# Eval("Text") %></
asp:Label>
<br />
<asp:Label runat="server" ID="MenuDesc"><%# Eval("ToolTip") %></
asp:Label>
</DynamicItemTemplate>
<Items>
<asp:MenuItem Text="Playback control">
<asp:MenuItem Text="Play" ToolTip="Start playback" />
<asp:MenuItem Text="Pause" ToolTip="Pause playback" />
<asp:MenuItem Text="Stop" ToolTip="Stop playback" />
</asp:MenuItem>
</Items>
</asp:Menu>
<br />
<asp:Button runat="server" ID="AddItem" Text="Add item"
OnClick="AddItem_Click" />
Example 2:
private void AddItem_Click(object sender, EventArgs e)
{
MenuItem newItem = new MenuItem();
newItem.Text = "New item";
newItem.ToolTip = "Newly added dynamic menu item";
PlaybackControl.Items[0].ChildItems.Add(newItem);
}