Reputation: 13310
I am trying to create a link in a user area of my website.
After logging in, the users info is passed to the allow access to specific areas of the site. What I would like to do is create an html link that is controlled by a conditional statement.
for example, after a user logs in, I want to check whether they have credentials to click on a link which will allow them to advance to something new. If they don't have the credentials, the link will be blocked out or not appear at.
I am looking for a place to start on this task, any documentation or keywords would be helpful. Also code samples would help greatly.
The page is an aspx page, with vb code behind.
Thanks in advance.
Upvotes: 2
Views: 2451
Reputation: 46067
I know this question was already answered, but if you're using the built-in role management, I've always preferred doing things this way:
<asp:HyperLink ID="HyperLink1" runat="server" Text="Some Protected Page" ... />
In code-behind:
HyperLink1.Visible = User.IsInRole("admin");
Upvotes: 1
Reputation: 61872
I would simply put your logic in the page load event.
ASPX:
<asp:HyperLink ID="myHyperLink" runat="server"></asp:HyperLink>
VB:
Protected Sub Page_Load(sender As Object, e As EventArgs)
If 1 = 1 Then
myHyperLink.Visible = False
End If
End Sub
ASPX Embedded Logic:
<asp:HyperLink ID="myHyperLink" runat="server"
Visible='<%# Eval("[Some Condition]") != null ? true : false %>'>
</asp:HyperLink>
Upvotes: 1