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

  • SEARCH
  • Home
  • 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 7756427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:49:16+00:00 2026-06-01T12:49:16+00:00

For my current project I am adding an variable amount of usercontrols : ucTask

  • 0

For my current project I am adding an variable amount of usercontrols : ucTask to my flowlayoutpanel : flpTasks

foreach (task t in tasks)
{
   ucTask uct = new ucTask();
   uct.id = t.task_id;
   uct.date= t.date.ToString();
   uct.btnNaam = t.task_id.ToString();

   uct.OnButtonclick += new EventHandler(uct_OnButtonclick);

   flpTasks.Controls.Add(uct);
}

ucTask

Now I will have a couple of those usercontrols in the flowlayoutpanel, and I want to fire an event when I press that button. With the EventHandler I can fire an event, but I need to fire a different event for a different button.

    void uco_OnButtonclick(object sender, EventArgs e)
    {
        lblStatus.Text = "TEST";
    }

I don’t know how to know which button (or usercontrol) I pressed. And I’m out of ideas, any suggestions?

Thanks,
Thomas

  • 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-06-01T12:49:18+00:00Added an answer on June 1, 2026 at 12:49 pm

    Sender of event is actually one of buttons. When you cast sender to Button type, you can access any of Buttons properties and determine which button was pressed:

    void uco_OnButtonclick(object sender, EventArgs e)
    {
       Button button = sender as Button;
       if (button == null)
           return;
    
       lblStatus.Text = button.Name;
    }
    

    UPDATE: after reading your question once again, I get that ucTask is actually UserControl, which rises event when button inside it was clicked.

    So, first is naming. Good style for class names in c# is PascalCase. E.g. for task user control good name will be TaskControl. Next goes event naming. It’s common to name events as EventName(-ing, -ed). If you want to raise event, then good style is protected method OnEventName(-int, -ed). And another remark – when you writing user controls, you are free to use business terms to name your events. E.g. TaskCreated, TaskChanged. And you also can pass any parameters to your event by creating custom EventArgs.

    So, for your user control:

    public class TaskChangedEventArgs : EventArgs
    {
        public TaskChangedEventArgs(int taskId)
        {
            TaskId = taskId;
        }
        public int TaskId { get; private set; }
    }
    
    public class TaskControl : UserControl
    {
       public event EventHandler<TaskChangedEventArgs> TaskChanged;
    
       // raise it inside button click event handler
       protected void OnTaskChanged(int taskId)
       {
           if (TaskChanged != null)
               TaskChanged(this, new TaskChangedEventArgs(taskId));
       }
    }
    

    When you use your user control, just subscribe to its TaskChanged event:

    uct.TaskChanged += new EventHandler<TaskChangedEventArgs>(uct_TaskChanged);
    

    And all parameters, that you passed via event argument will be available in that event handler:

    void uco_TaskChanged(object sender, TaskChangedEventArgs e)
    {
        lblStatus.Text = e.TaskId.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try adding a new data source to my project I get a
In my current project I am adding a DropDownExtender (from the AJAX toolkit) to
I am adding a feature to my current project that will allow network admins
My current project is in Rails. Coming from a Symfony (PHP) and Django (Python)
My current project uses NUnit for unit tests and to drive UATs written with
My current project involves deploying an upgraded .exe file that runs as a Windows
My current project involves writing Perl code inside a Solaris VMWare appliance (hosted on
My current project is broken down into 3 parts: Website, Desktop Client, and a
Our current project has ran into a circular dependency issue. Our business logic assembly
On my current project, we've been using Struts 1 for the last few years,

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.