Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Click Event not fired in User Control when multiple instances are created

I've a user control with 2 labels and two textboxes. When the label is clicked the textbox's visible prop is set to true. Here's the code I've used:

    private void label_Heading_Click(object sender, EventArgs e)
    {
        label_Heading.Visible = false;
        textBox_Heading.Text = label_Heading.Text;
        textBox_Heading.Visible = true;
        textBox_Heading.Focus();
    }

After the textbox lose focus, it's visible prop is set to false and the label is updated with the text. Code:

    private void textBox_Heading_Leave(object sender, EventArgs e)
    {
        textBox_Heading.Visible = false;
        if(textBox_Heading.Text != "")
            label_Heading.Text = textBox_Heading.Text;
        label_Heading.Visible = true;
    }

The code to create user controls on click:

    private void label1_Click(object sender, EventArgs e)
    {
        TaskCard _taskCard = new TaskCard(++TOTAL_ITEM_COUNT, PanelName);
        panel_DeletedItem.Controls.Add(_taskCard);
        panel_DeletedItem.Refresh();
    }

These code work fine when a single user control of this type is added to a panel. But if I add more than one, the code works only for the first user control, but it wont work for the new ones, although the event is fired for every user control. What am I missing here? Please suggest.

If I add a mbox to this code, the mbox is displayed for any control, but the rest of the code won't work, except for the first one.

    private void label_Heading_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Test"); // this will display, but the rest of the code is not executed or changes are not visible, i.e., the teboxes are not displayed even if I click the labels
        label_Heading.Visible = false;
        textBox_Heading.Text = label_Heading.Text;
        textBox_Heading.Visible = true;
        textBox_Heading.Focus();
    }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!