Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning Visible Property of the Button to a Static Method Result

Tags:

.net

css

asp.net

I am trying to hide the button based on the user's role using the following code:

 <asp:Button ID="btndisplayrole" Text="Admin Button" Visible='<%= WebApplication1.SiteHelper.IsUserInRole("Admin") %>' runat="server" OnClick="DisplayRoleClick" />

But when I run the above code I get the following error message:

Cannot create an object of type 'System.Boolean' from its string representation '<%= WebApplication1.SiteHelper.IsUserInRole("Admin") %>' for the 'Visible'

like image 641
azamsharp Avatar asked Dec 15 '08 21:12

azamsharp


1 Answers

As an alternative solution:

<% if (WebApplication1.SiteHelper.IsUserInRole("Admin"))
    {%>
        <asp:Button ID="btndisplayrole" 
                    Text="Admin Button" 
                    runat="server" 
                    OnClick="DisplayRoleClick" /> 
<%} %>
like image 190
Adam Marshall Avatar answered Oct 27 '22 02:10

Adam Marshall