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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:05:56+00:00 2026-05-20T05:05:56+00:00

The web user control: FilterLabel <span style= display:block; float:left; margin:5px; padding: 5px; border: 1px

  • 0

The web user control: FilterLabel

<span style=" display:block; float:left; margin:5px; padding: 5px; border: 1px inset #000000; font-family: Tahoma; font-size: small;">
<asp:Label ID="lblFilterDisplay" runat="server" Text="Product/Service: This is a testing"></asp:Label>
&nbsp;
<asp:ImageButton ID="btnRemove" runat="server" ImageUrl="~/Images/remove.png" OnClick="btnRemove_Click" />

And the part of behind codes for this web user control:

public event EventHandler RemoveClick;
......
public void btnRemove_Click(object sender, EventArgs e)
{
    if (RemoveClick != null)
        RemoveClick(this, EventArgs.Empty);
}

Next, the web user control “FilterLabel” will be used in another web user control “FilterList”:

<%@ Register TagPrefix="uc" TagName="FilterLabel" Src="~/Controls/FilterLabel.ascx" %>
<asp:Panel ID="FilterList" runat="server" Width="100%" GroupingText="Filter List" CssClass="filterList">
</asp:Panel>

And the part of behind codes of this web user control is:

protected override void OnInit(EventArgs e)
{
    if (IsPostBack)
    {
        BindFilters();
    }

}

public void BindFilters()
{
    List<FilterLabel> filters = Filters;
    foreach (FilterLabel filter in filters)
    {
        FilterList.Controls.Add(filter);
    }
}

public List<FilterLabel> Filters
{
    get
    {
        List<FilterLabel> filters = Session["Filters"] as List<FilterLabel>;
        if (filters == null)
        {
            filters = new List<FilterLabel>();
        }
        return filters;
    }
}

public void AddFilter(string filterName, string filterContent, string filterValue = null)
{
    FilterLabel filter = LoadControl("~/Controls/FilterLabel.ascx") as FilterLabel;
    filter.ID = "Filter";
    filter.FilterContent = filterContent;
    filter.FilterName = filterName;
    filter.Value = filterValue;
    filter.RemoveClick += new EventHandler(RemoveFilter);
    List<FilterLabel> filters = Filters;
    filters.Add(filter);
    Session["Filters"] = filters;
    BindFilters();
}

private void RemoveFilter(object sender, EventArgs e)
{
    //some handling codes
}

So now the problem is the btnRemove_Click event isn’t activated when I click the image button “btnRemove”.

  • 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-20T05:05:57+00:00Added an answer on May 20, 2026 at 5:05 am

    You should try with bubble event. with your solution you will need on each postback to rebind event handler on each usercontrol for existing filters

    public int FilterCount 
    {
        get{
            if(ViewState["filter_count"] == 0){
                FilterCount = 0;
            }
            return (int)ViewState["filter_count"];
        }
        set{
            ViewState["filter_count"] = value;
        }
    }
    
    protected void RecreateFilterControlls()
    {
        for(int i =0; i < FilterCount; i++){
            FilterLabel filter = LoadControl("~/Controls/FilterLabel.ascx") as FilterLabel;
            FilterList.Controls.Add(filter);
            filter.RemoveClick += new EventHandler(RemoveFilter);
        }
    }
    
    
    protected override void OnInit(EventArgs e)
    {
        if (IsPostBack)
        {
            RecreateFilterControlls();
        }
    
    }
    // this is for button which will add new FilterLabel UserControl
    protected void AddNewFilter_Click(object sender, EventArgs e)
    {
        // just create filter
        AddFilter(<FilterNameTextBox|combobox>, <FilterContentTextBox>, <filterValue>);
    }
    
    
    public void AddFilter(string filterName, string filterContent, string filterValue = null)
    {
        FilterLabel filter = LoadControl("~/Controls/FilterLabel.ascx") as FilterLabel;
        filter.ID = "Filter";
        filter.FilterContent = filterContent;
        filter.FilterName = filterName;
        filter.Value = filterValue;
        filter.RemoveClick += new EventHandler(RemoveFilter);
        // increament filter count
        FilterCount++;
    
    }
    
    private void RemoveFilter(object sender, EventArgs e)
    {
        //some handling codes
        //remove control which caused this event
        FilterList.Controls.Remove(sender); // or you will need to ask for IndexOf(sender);
        FilterCount--;
    }
    

    the rest will be handled by ViewState it self, so you don’t need to bind data back to FilterLabel back

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

Sidebar

Related Questions

I have a web user control that contains several other (web user) controls and
I have a web user control with a dropdownlist inside of it. When the
When you create a new web user control in visual studio it by default
I have an ASP.Net web user control that contains a TextBox and a calendar
I have an int array as a property of a Web User Control. I'd
Can you use FluentHTML or other alternatives in an web application user control? Can
Currently I'm registering every user control separately in Web.config <pages validateRequest=false> <controls> <add tagPrefix=cc1
We need a special user control for our web application. It should ideally look
I've got an web user control with an updatepanel. On my mainpage I got
I have a Web User Control I created for authentication. The web user control

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.