I have developed a custom Web Control that acts as a container for a mobile banner, but I want to hide it from users who are admins.
So far, I've attempted the following:
<mob:MobileBanner runat="server" ID="MobileBanner" Visible='<%# Not HttpContext.Current.User.IsInRole("Admin") %>' />
Unfortunately, this approach doesn't seem to be working as expected.
I also considered wrapping the HTML code in a conditional check to display the advertisement content only if the user is not an admin, along with the necessary CSS link.
Although there is a similar query regarding enabling and disabling buttons based on user roles (referenced here), it pertains to ASP.NET Server Side buttons rather than a basic Web Control designed for holding HTML elements.
If anyone requires the implemented code, simply add a new Web Control to your project and paste the following snippet:
<link href = "my_css_file_here.css" rel="stylesheet" type="text/css" />
<div Class="my_banner_container">
<!--Insert your banner code here-->
</div>
An alternative solution involves creating a server-side container within the master document and applying the following logic:
my_container.Visible = Not HttpContext.Current.User.IsInRole("Admin")
Additionally, you may need to adjust the padding-top property from 130px to 50px depending on the user's role status, requiring dynamic changes when an admin logs in or out.
For non-admins, consider utilizing a specific CSS file:
<link href = "my_css_file_130_here.css" rel="stylesheet" type="text/css" runat="server" />
Meanwhile, admins can use a different CSS file:
<link href = "my_css_file_50_here.css" rel="stylesheet" type="text/css" runat="server" />
Incorporate two distinct CSS files affecting the padding-top attribute and alter the href based on the user's admin privileges or lack thereof.
body {
padding-top: 130px;
}
or
body {
padding-top: 50px;
}
If you have any suggestions on how to streamline this process or propose a more efficient method, please share your ideas!