Solved

add property to asp.net page

Posted on 2009-04-02
2
240 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now