Currently, I am integrating Bootstrap into an ASP.NET application using C#. Within this application, I have implemented a two-level menu system where certain options are available to users and others are only visible to administrators. The decision on which links to display or hide is made during the page load in the master page. Everything works smoothly in desktop mode; however, in mobile view, the hidden links that should only be visible to administrators are also being displayed.
<ul class="navbar-nav">
<li class="nav-item active">
<asp:LinkButton class="nav-link" ID="LinkButton5" runat="server" Visible="false" PostBackUrl="#">Link 01</asp:LinkButton>
</li>
<li class="nav-item active">
<asp:LinkButton class="nav-link" ID="LinkButton6" runat="server" Visible="false" PostBackUrl="#">Link 02</asp:LinkButton>
</li>
<li class="nav-item active">
<asp:LinkButton class="nav-link" ID="LinkButton4" runat="server" Visible="false" PostBackUrl="#">Link 03</asp:LinkButton>
</li>
<li class="nav-item active">
<asp:LinkButton class="nav-link" ID="LinkButton2" runat="server" Visible="false" PostBackUrl="#">Link 04</asp:LinkButton>
</li>
<li class="nav-item active">
<asp:LinkButton class="nav-link" ID="LinkButton7" runat="server" Visible="false" PostBackUrl="#">Link 05</asp:LinkButton>
</li>
<li class="nav-item dropdown">
<a runat="server" class="nav-link dropdown-toggle" href="#" id="dropdown04" data-toggle="dropdown" aria-expanded="false" aria-haspopup="true" Visible="false">Link With Sub Menu</a>
<div class="dropdown-menu" aria-labelledby="dropdown04">
<a class="dropdown-item" href="#">Sublink 01</a>
<a class="dropdown-item" href="#">Sublink 02</a>
<a class="dropdown-item" href="#">SubLink 03</a>
</div>
</li>
<li class="nav-item active">
<asp:LinkButton class="nav-link" ID="LinkButton1" runat="server" Visible="true" PostBackUrl="#">Link 06</asp:LinkButton>
</li>
<li class="nav-item active">
<asp:LinkButton class="nav-link" ID="LinkButton3" runat="server" Visible="False" OnClick="LinkButton3_Click">Link 07</asp:LinkButton>
</li>
</ul>
The associated code determines which menu options are visible based on the role of the logged-in user:
if (Session["PersonType"] != null && Session["PersonType"].Equals("Admin"))
{
LinkButton1.Visible = false;
LinkButton2.Visible = false;
dropdown04.Visible = true;
LinkButton3.Visible = true;
LinkButton4.Visible = false;
LinkButton5.Visible = true;
LinkButton6.Visible = true;
LinkButton7.Visible = true;
}
else
{
LinkButton1.Visible = true;
LinkButton2.Visible = true;
LinkButton3.Visible = false;
LinkButton4.Visible = true;
LinkButton5.Visible = false;
LinkButton6.Visible = false;
LinkButton7.Visible = false;
dropdown04.Visible = false;
}
The issue arises in the mobile view where the dropdown menu items in dropdown04 are displayed regardless of the user's role. This problem is isolated to the mobile view and does not affect the desktop mode. Some users have proposed changing data-toggle to data-bs-toggle and data-target to data-bs-target, but this solution did not resolve the issue and instead prevented the menu from expanding in the mobile view.