I have a link which I have set visibility hidden. However if a certain role logs in I want them to see the link. How do I do this. Help please.
The key being the runat="server".
This allows the code behind to see the control and then you can set the .visible property.
I suppose that this could depend on how your application is set up, but if you are using the built-in Role Provider, you could use something like this :
//Check if your user is in a specific role
if(Roles.IsUserInRole("Your Role"))
{
//Execute this code if the current user is in the "Your Role" role (using CSS attributes)
YourLink.Style["visibility"] = "visible";
//Or if you have actually hidden the link, use the Visible property
YourLink.Visible = true;
}
//If you are using the second version, you could simplify it to this
YourLink.Visible = Roles.IsUserInRole("Your Role");
This assumes your are using a HyperLink Control or an element with the runat="server" property set so that it can be accessed from your code-behind :