Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6065899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:26:33+00:00 2026-05-23T09:26:33+00:00

I’m trying to create a control that can extend other webcontrols and set some

  • 0

I’m trying to create a control that can extend other webcontrols and set some properties like visible and enabled, based on user permissions.

Here’s an example where your user role would need to include the “CanSave” permission:

<asp:Button ID="btn1" runat="server" Text="Save"/>
<myControls:PermissionsExtender runat="server" ControlToSet="btn1" Permission="CanSave"/>

I’m trying to keep this reusable, that’s why the PermissionExtender is in a separate project that can not have any dependencies to other projects. To make a decision, the control of course needs to get this info from somewhere else (database or something). I made another control and, using events, the above extender will be set by a master control, so only that needs to know where to look up the information.

The master control now needs to be configured to know where the information about roles and permissions will be coming from. My idea was to have an interface inside the reusable project, and implement that somewhere else, then configure my control to go and find the class that implements the method I need and load it through reflection. But I’m unclear how this could work. I would probably place the master control in the masterpage and supply it a class name like PermissionClass=”SecurityLibrary.PermissionsClass”. Kinda like ObjectDatasource does it, but other suggestions are welcome.

The method signature would be like:
bool HasPermission(string permission)
It would know the current users role and using that combination, looks up if the role includes the permission.

How can I wire up a call from the control to a method inside my main project that can supply the necessary information without making them dependent.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:26:33+00:00Added an answer on May 23, 2026 at 9:26 am

    I think I’ve got something that will work for you (tested fine for me but I may have misunderstood part of what you were looking for). With this implementation the asp.net designer code will look like this:

        <web:PermissionMasterControl runat="server" ID="masterController" PermissionClass="SecurityLibrary.RandomPermissionClass" />
    
        <asp:Button ID="btnSave" runat="server" Text="save" />
        <web:PermissionExtender runat="server" ControlToSet="btnSave" Permission="CanSave" MasterControllerID="masterController" />
    

    Now for the SecurityLibrary. Pretty straight forward, I included a simple “RandomPermissionClass” that randomly returns true/false.

    Namespace SecurityLibrary
        Public MustInherit Class PermissionClass
            Public MustOverride Function HasPermission(ByVal permission As String) As Boolean
        End Class
    
        Public Class RandomPermissionClass
            Inherits PermissionClass
    
            Private rand As New Random()
    
            Public Overrides Function HasPermission(permission As String) As Boolean
                Return If(rand.Next(2) = 0, False, True)
            End Function
        End Class
    End Namespace
    

    Now we have the “myControls” library, which contains no references to SecurityLibrary. I created two controls and a delegate. The controls are “PermissionMasterControl” and “PermissionExtender”. The delegate is what is used to actually perform the check against the reflected object.

    Namespace myControls
        Public Delegate Function HasPermissionDelegate(ByVal permission As String) As Boolean
    
        Public Class PermissionMasterControl
            Inherits System.Web.UI.Control
    
            Public Property PermissionClass As String
                Get
                    Return If(ViewState("PermissionClass") Is Nothing, "", ViewState("PermissionClass").ToString())
                End Get
                Set(value As String)
                    ViewState("PermissionClass") = value
                End Set
            End Property
    
            Private ReadOnly Property PermissionDelegate As HasPermissionDelegate
                Get
                    If _permissionDel Is Nothing Then
                        If Not String.IsNullOrEmpty(PermissionClass) Then
                            Dim t = Type.GetType(PermissionClass, False)
    
                            If t IsNot Nothing Then
                                _permissionObj = Activator.CreateInstance(t)
    
                                Dim mi As MethodInfo = _
                                        t.GetMethod("HasPermission", BindingFlags.Public Or BindingFlags.Instance)
    
                                _permissionDel = [Delegate].CreateDelegate(GetType(HasPermissionDelegate), _permissionObj, mi)
    
                            End If
                        End If
                    End If
    
                    Return _permissionDel
                End Get
            End Property
    
            Private _permissionObj As Object = Nothing
            Private _permissionDel As HasPermissionDelegate = Nothing
    
            Public Function HasPermission(ByVal permission As String) As Boolean
                If PermissionDelegate Is Nothing Then
                    Throw New NullReferenceException("The specified permission class (" + PermissionClass + ") could not be loaded/found.")
                End If
    
                Return PermissionDelegate(permission)
            End Function
        End Class
    
        Public Class PermissionExtender
            Inherits System.Web.UI.Control
    
            Public Property ControlToSet As String
                Get
                    Return If(ViewState("ControlToSet") Is Nothing, "", ViewState("ControlToSet").ToString())
                End Get
                Set(value As String)
                    ViewState("ControlToSet") = value
                End Set
            End Property
    
            Public Property Permission As String
                Get
                    Return If(ViewState("Permission") Is Nothing, "", ViewState("Permission").ToString())
                End Get
                Set(value As String)
                    ViewState("Permission") = value
                End Set
            End Property
    
            Public Property MasterControllerID As String
                Get
                    Return If(ViewState("MasterControllerID") Is Nothing, "", ViewState("MasterControllerID").ToString())
                End Get
                Set(value As String)
                    ViewState("MasterControllerID") = value
                End Set
            End Property
    
            Protected ReadOnly Property MasterController As PermissionMasterControl
                Get
                    If _mastercontroller Is Nothing Then
                        _mastercontroller = Me.Page.FindControl(MasterControllerID)
                    End If
    
                    Return _mastercontroller
                End Get
            End Property
    
            Protected ReadOnly Property ManagedControl As Control
                Get
                    If _controlToSet Is Nothing Then
                        _controlToSet = Me.NamingContainer.FindControl(ControlToSet)
                    End If
    
                    Return _controlToSet
                End Get
            End Property
    
            Private _controlToSet As Control = Nothing
            Private _mastercontroller As PermissionMasterControl = Nothing
    
    
            Protected Overrides Sub OnLoad(e As System.EventArgs)
                MyBase.OnLoad(e)
    
                Dim bResult As Boolean = MasterController.HasPermission(Permission)
    
                ManagedControl.Visible = bResult
            End Sub
        End Class
    End Namespace
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.