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 3231408
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:02:31+00:00 2026-05-17T17:02:31+00:00

I want to make panels Visibility true or false based on a result of

  • 0

I want to make panels Visibility true or false based on a result of a Func.

I have a page with controls as in the following code:

<asp:Panel ID="Panel2" runat="server">
    <asp:Panel ID="Panel3" runat="server">
        <c:PermissionPanel ID="P1" runat="server" ValidationGroup="Val1">
            Validation Group 1 - OK
        </c:PermissionPanel>
    </asp:Panel>
</asp:Panel>

<c:PermissionPanel ID="P2" runat="server" ValidationGroup="Val1">
    Validation Group 1 - OK
</c:PermissionPanel>

<hr />

<c:PermissionPanel ID="P3" runat="server" ValidationGroup="Val2">
    Validation Group 2 - OK
</c:PermissionPanel>

<asp:Panel ID="Panel4" runat="server">
    <asp:Panel ID="Panel1" runat="server">
        <c:PermissionPanel ID="P4" runat="server" ValidationGroup="Val2">
            Validation Group 2 - OK
        </c:PermissionPanel>
    </asp:Panel>
</asp:Panel>

In short I have 4 PermissionPanel that can be inside other controls.

The code of the PermissionPanel is the following:

public class PermissionPanel : Panel
{
    public delegate bool OnValidate();
    public event OnValidate Validate;

    public string ValidationGroup { get; set; }

    protected override void OnPreRender(EventArgs e)
    {
        this.Visible = (Validate != null ? Validate() : false);

        base.OnPreRender(e);
    }
}

I want to get all PermissionPanels from the page and add an event on each accordingly to its group, for example:

protected void Page_Load(object sender, EventArgs e)
{
    // Magic code here. Linq is very welcome
    // GetPageControls<PermissionPanel>("Val1").AddEvent(() => return true);
    // GetPageControls<PermissionPanel>("Val2").AddEvent(() => return false);
}

The code above would make all panels with ValidationGroup == Val1 visible while Val2 would not be rendered.

So the questions are: How can I achieve this? Is there a better way of doing it?


In short I want to add a Func that will be a validation method allowing the panels to be shown or not. A real example is:

// If post owner is the logged user, show controls like edit and delete
() => return (user != null && user.ID == post.UserID);
  • 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-17T17:02:32+00:00Added an answer on May 17, 2026 at 5:02 pm

    There is two ways that I´m aware of: searching or self-registering. In searching you´ll get every control in the control hierarchy starting by the page, recursively and checking if it is a PermissionPanel.

    The second way, self-registering which I like you´ll update PermissionPanel to register itself in a list inside Page.Items and register your validation handler only for controls in this list.

    On PermissionPanel you can do something like that:

    protected override void CreateChildControls()
    {
         base.CreateChildControls();
    
         List <PermissionPanel> panels;
    
         if (Page.Items["PermissionPanels"] == null)
             Page.Items["PermissionPanels"] = panels = new List <PermissionPanel>();
         else
             panels = Page.Items["PermissionPanels"] as List <PermissionPanel>;
    
         panels.Add(this);
    }
    

    And on page OnPreRender you can iterate over Page.Items["PermissionPanels"] and registering validation handlers according to your validation group.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 panels and I want to make drags on them. The problem
i tried Visible='<%#Convert.ToBoolean(((Session[AccountId].ToString()==1)|| (Session[AccountID].ToString()==))?true:false) %>' i want to make panel visible=true when session id=1
I want to make sure that a set of functions have the same signature
I want to make a login system using ASP.NET (MVC). On the internet, I
I have a jQuery tab section - and I want to animate the panels
Hey there, I'm trying to make a site which have following: News, Products, About
I have a bunch of panels with different markup. I want to reuse the
I want to make window with few panels. I can append one to MainFrame's
I want to make an etag that matches what Apache produces. How does apache
I want to make a table in SqlServer that will add, on insert, a

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.