Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Iterating Controls

Iterating Controls

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netgame-devhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    afronaut
    wrote on last edited by
    #1

    Hello all, I'm trying to implement a "user rights" system in our web application. I've done a few underpinnings but I'd like to centralize it. The following is the code I use: public void EnforcePerms(Control parent, DataTable pSet){ foreach (Control c in parent.Controls) { if(c is LinkButton){ LinkButton lbc = (LinkButton)c; if(DBContain(lbc.ID, pSet)){ lbc.Enabled = false; lbc.BackColor = Color.Gainsboro; // lbc.Attributes.Add("class","rightsblock"); } } if(c is HyperLink){ HyperLink hpc = (HyperLink)c; if(DBContain(hpc.ID, pSet)){ hpc.Enabled = false; hpc.BackColor = Color.Gainsboro; // lbc.Attributes.Add("class","rightsblock"); } } if (c.Controls.Count > 0) { EnforcePerms(c, pSet); } } } The problem is that I have to paste this on each page because it's recursive. I'd like to have a central class though that takes a ref parameter to the controls collection on an ASP.NET page and then enforces the permissions in a central location. Any suggestions? Has anyone who has done this before tell me if there's a better way? *->>Always working on my game, teach me *->>something new. cout << "dav1d\n";

    J 1 Reply Last reply
    0
    • A afronaut

      Hello all, I'm trying to implement a "user rights" system in our web application. I've done a few underpinnings but I'd like to centralize it. The following is the code I use: public void EnforcePerms(Control parent, DataTable pSet){ foreach (Control c in parent.Controls) { if(c is LinkButton){ LinkButton lbc = (LinkButton)c; if(DBContain(lbc.ID, pSet)){ lbc.Enabled = false; lbc.BackColor = Color.Gainsboro; // lbc.Attributes.Add("class","rightsblock"); } } if(c is HyperLink){ HyperLink hpc = (HyperLink)c; if(DBContain(hpc.ID, pSet)){ hpc.Enabled = false; hpc.BackColor = Color.Gainsboro; // lbc.Attributes.Add("class","rightsblock"); } } if (c.Controls.Count > 0) { EnforcePerms(c, pSet); } } } The problem is that I have to paste this on each page because it's recursive. I'd like to have a central class though that takes a ref parameter to the controls collection on an ASP.NET page and then enforces the permissions in a central location. Any suggestions? Has anyone who has done this before tell me if there's a better way? *->>Always working on my game, teach me *->>something new. cout << "dav1d\n";

      J Offline
      J Offline
      Jesse Squire
      wrote on last edited by
      #2

      How about making a base class for your pages? Create a class that inherits from System.Web.UI.Page and includes your method. The other pages in your application would then inherit from your base page class. The final product would look something like:

      public class MyPageBase : System.Web.UI.Page 
      { 
      protected void EnforcePerms() 
      { 
      DataSet pSet = GetPSet(); 
       
      foreach (Control in this.Controls) 
      { 
      // Do work  } 
      } 
      } 
       
      // The rest of the pages would inherit from MyPageBase  
      public class WebForm1 : MyPageBase 
      { 
      private void Page_Load(object sender, System.EventArgs ea) 
      {

      A 1 Reply Last reply
      0
      • J Jesse Squire

        How about making a base class for your pages? Create a class that inherits from System.Web.UI.Page and includes your method. The other pages in your application would then inherit from your base page class. The final product would look something like:

        public class MyPageBase : System.Web.UI.Page 
        { 
        protected void EnforcePerms() 
        { 
        DataSet pSet = GetPSet(); 
         
        foreach (Control in this.Controls) 
        { 
        // Do work  } 
        } 
        } 
         
        // The rest of the pages would inherit from MyPageBase  
        public class WebForm1 : MyPageBase 
        { 
        private void Page_Load(object sender, System.EventArgs ea) 
        {

        A Offline
        A Offline
        afronaut
        wrote on last edited by
        #3

        Thanks Jesse. I had thought of inheritance but your suggestion made me tinker a bit and it works really, really well. *->>Always working on my game, teach me *->>something new. cout << "dav1d\n";

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups