Solved

add property to asp.net page

Posted on 2009-04-02
2
244 Views
Last Modified: 2012-05-06
I have asp.net app using master page

I need to have a hyperlink that is displayed on page if a user is in a certain role.
I need an elegant solution to this, I am using   .net 3.5
0
Comment
Question by:mugsey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 250 total points
ID: 24050257
I'm not sure of an elegant solution, but you could place a button and set visible to false. Then in the page_load() of the code behind detect if the user is in the correct role and set visible to true.

The code below is for a linkbutton, but it should work with any control.

Hope this helps,
Dustin
 <asp:LinkButton ID="lbdelbtn" runat="server" CausesValidation="False" PostBackUrl="deleterec.aspx" Visible="False">Delete Record</asp:LinkButton>
 
 
If User.IsInRole("Admins") Then
            lbdelbtn.Visible = True
        End If

Open in new window

0
 
LVL 23

Assisted Solution

by:apresto
apresto earned 250 total points
ID: 24050258
Why dont you create the control
<asp:Hyperlink runat="server" visible="false"
and change the visible property based on the users role in the codebehind.
Either that, or you could create the hyperlink on the fly and add it to a placeholder or tablecell
HyperLink link = new HyperLink();
link.NavigationURl = "???";
etc
Yourcontainer.Controls.Add(link);
If you choose this method i would suggest you have it in your Page_Init event rather than the page_load
 
 
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question