Menu item dynamic text

S

Steven Cheng[MSFT]

Hello Chuck,

From your description, you're wantting to display the current user identity
name in a certain MenuItem's Text field, correct?

As for the ASP.NET 2.0 Menu control, since the MenuItem inside it is not a
server control and doesn't support DataBindign event, therefore, you can
not use <% %> or <%# %> expression directly in it.

So far based on my research, I think you can consider the following
approach which require us to customize the MenuItem's template and add
custom function to do the MenuItem rendering. Here is the test page code( I
use inline server-side code)

==============test page================
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="c#" runat="server">
string GetText(string text, string value)
{
Response.Write("<br/>Text: " + text + ", value: " + value);
if (value == "Logout")
{
return Context.User.Identity.Name;
}
else
{
return text;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu ID="Menu1" runat="server">
<DynamicItemTemplate>
<%# GetText(Eval("Text", "{0}"), Eval("Value", "{0}"))%>
</DynamicItemTemplate>
<StaticItemTemplate>
<%# GetText(Eval("Text", "{0}"), Eval("Value", "{0}"))%>
</DynamicItemTemplate>
</StaticItemTemplate>
<Items>
</asp:MenuItem>
<asp:MenuItem Text="New Item" Value="New
Item"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="New Item" Value="New Item">
<asp:MenuItem Text="New Item" Value="New
Item"></asp:MenuItem>
<asp:MenuItem Text="New Item" Value="New
Item"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Logout" Value="Logout" ></asp:MenuItem>
</Items>
</asp:Menu>

</div>
</form>
</body>
</html>
============================================

In the above page, I use the <StaticItemTemplate> and <DynamicItemTemplate>
to customize the rendering UI of each menu item. However, since you only
want to display custom text for some particular menu item(depend on the
text or value), I add a custom helper function to do the detection and
return the correct text for displaying.

Hope this helps. If there is any further questions on this, please feel
free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hello Chuck,

Have you got any further progress on this issue or does the suggestion in
my last reply helps you some? If there is anything else we can help, please
feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top