Groups | Blog | Home
all groups > asp.net webcontrols > december 2006 >

asp.net webcontrols : What is syntax for Eval(User.IsInRole) to return True/False To Vis


Morris Neuman
12/28/2006 4:48:00 PM
I am trying to set the Visible property attribute of a asp:HyperLink control
based on the user's membership role. If the user role is administrator then
I want to display the hyperlink, if not then I want the hyperlink to be
invisible.

I tried setting:
Visible="<%# Eval(Convert.ToString(User.IsInRole ("administrator")))%>"

This gives me server tag is not well formed error. I have tried variations
for the syntax but have not had any success.

Any help/guidance would be appreciated.
--
Thanks
stcheng NO[at]SPAM online.microsoft.com
12/29/2006 7:34:24 AM
Hello Morris,

As for the databinding expression in your scenario, you do not need to use
"Eval" function since it is used for retrieved data field value from
datasource item only. You can simply put the boolean expression in
databinding block directly as below:

======================
<asp:Button ID="btn1" runat="server" Text="Show TextBox1"
.............
Enabled='<%# User.IsInRole("administrator") %>'/>

======================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.


MikeS
1/3/2007 7:09:21 AM
Perhaps a loginview control will work for you.

<asp:LoginView ID="LoginView1" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="Administrator">
<ContentTemplate>
<asp:HyperLink ID="HyperLink1"
runat="server">HyperLink</asp:HyperLink>
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
AddThis Social Bookmark Button