Menu item dynamic text

Discussion in 'ASP .Net Web Controls' started by Chuck P, Mar 7, 2007.

  1. Chuck P

    Chuck P Guest

    Is it possible to put the Current.User.Identity Name in the menu?
    Something like this.

    <asp:MenuItem NavigateUrl="http://hrauth.lanl.gov/logout.aspx" Text="Log Out
    <% =HttpContext.Current.User.Identity.Name %> " Value="Log Out">
    </asp:MenuItem>
     
    Chuck P, Mar 7, 2007
    #1
    1. Advertising

  2. 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 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="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.
     
    Steven Cheng[MSFT], Mar 8, 2007
    #2
    1. Advertising

  3. 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.
     
    Steven Cheng[MSFT], Mar 13, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gino
    Replies:
    12
    Views:
    1,088
    Keith Wansbrough
    Sep 1, 2004
  2. Replies:
    0
    Views:
    1,499
  3. BlueFlash
    Replies:
    2
    Views:
    485
    John Ladasky
    Aug 26, 2009
  4. mwr

    ASP.Menu in IE6, cannot select menu item when...

    mwr, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    268
  5. SpamProof
    Replies:
    0
    Views:
    199
    SpamProof
    Jan 25, 2004
Loading...

Share This Page