Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6825969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:05:35+00:00 2026-05-26T22:05:35+00:00

I have two user controls (ascx); one contains some forms, and the other one

  • 0

I have two user controls (ascx); one contains some forms, and the other one contains the menu bar.

I used both of them in many pages. Now, I need to customize the one that has the menu bar for the Admin Homepage. So, is it possible to add some changes to the user control just for this page.

I mean by changes, adding two elements to the menu bar.

For instance, let us assume that the two pages are called: Admin, Settings. How will you customize the user control for them?

My code for the Menu User Control (ascx file):

<div class="topnav">
            <ul class="menu" runat="server" >
                <li><a href="Default.aspx">Home</a></li>
                <li><a href="#">Sub-Menu1</a>
                    <ul>
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Item</a></li>
            <li><a href="#">Item</a></li>
                    </ul>
                </li>
                <li><a href="#x">Sub-Menu2</a>
                    <ul>        
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Item </a></li>
                        <li><a href="#">Item</a></li>
                        <li><a href="#">Item</a></li>
                    </ul>
                </li>
                <li><a href="#">ITEM</a></li>
                <li><a href="About.aspx">About</a></li>
                <li><a href="Contact.aspx">Contact Us</a></li>
                <li><a href="#">Help</a></li>
                <li class="menuItem1ToHide"><a href="#">Admin</a></li>
            </ul>
            <div class="clr"></div>
          </div>

And inside the Master Page, I put:

<uc1:MenuBar ID="MenuBar1" runat="server" />

As you see from above code, I added the Admin page as the last element in the list, and the code-behind class, I added the bool method mentioned below, but I don’t know how to make the last element only visible for the Admin rather than the other users

By the way, I am using the ASP.NET Role-Based Security since I am using the Windows Authentication. This to define the Admin from the Normal User.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:05:36+00:00Added an answer on May 26, 2026 at 10:05 pm

    Sure,

    Add the two items to the menu bar, and hide them for everything but the admin page. You can do that in several ways; check the URL of the current request, or add a property to the user control (default the menu items to false).

    public bool DisplayAdminOnlyMenuItems
    {
      get { return menuItem1ToHide.Visible; }
      set
      {
         menuItem1ToHide.Visible = value;
         menuItem2ToHide.Visible = value;
      }
    }
    

    or you can use a method to do it. The property allows you to set it in markup or code. For instance, if your UC definition was this:

    <uc:Menu ID="ucMenu" runat="server" />
    

    You can set it, for the admin page, this way:

    <uc:Menu ID="ucMenu" runat="server" DisplayAdminOnlyMenuItems="True" />
    

    And then it will make those menu items visible.

    EDIT: In your case, since everything is role security, add runat=”server” to the LI to show or hide:

    <li id="liAdmin" runat="server" class="menuItem1ToHide"><a href="#">Admin</a></li>
    

    In your code, on prerender of the user control, do:

    protected override void OnPreRender(EventArgs e)
    {
        liAdmin.Visible = this.User.IsInRole("Admin");
        //if visible isn't available, use style["display"] = (this.User.IsInRole("Admin") ? "" : "none";
    }
    

    Something like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created some Web User Controls (.ascx files) and dropped them into Pages. The
I have two user controls in my ASP.Net project, one that is explictly for
I have two tabitems. User will enter some data and save it on the
I have two user controls A and B, where B depends on the existence
I have a window (Windows form ) where i have two WPF user controls
In a webpart I have two user controls loaded. I want to be able
I have two instances of a user control on a page. Both have fields
I have two user controls that need to add a class atribute to the
i have two user controls uc1 and uc2. uc1 as button and uc2 has
I'm building a SL4 app. I have two controls, a top search bar and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.