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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:48:07+00:00 2026-05-22T17:48:07+00:00

I have a user control and I want the developer who drops the user

  • 0

I have a user control and I want the developer who drops the user control on the winform, can tests some values before this user control does something

I want to know if my method is good and if there is a better way to do this ?

Actually in my user control, I have a collection of List<IValidator> which is exposed publicly, to the developer could add IValidator which has implemented. This interface implements only a bool Validate() method.

The user control have a method named Validate() which iterate on the List<IValidator> collection and calls Validate() method.

Here is the code :

public partial class MyUserControl : UserControl
{
    private SqlConnection _connection;
    private List<IValidator> _validators;


    private void button1_Click(object sender, EventArgs e)
    {
        Validate();
    }

    private bool Validate()
    {
        foreach (IValidator validator in this.Validators)
        {
            validator.Validate();
        }
    }


    public List<IValidator> Validators
    {
        get { return _customValidators; }
        set { _customValidators = value; }
    }

}

And the code in the winform hosting the user control :

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Validator val1 = new Validator();
        myUserControl1.Validators.Add(val1);
    }
}


public class Validator : IValidator 
{
    public bool Validate()
    {
        return true;
    }
}

I would know if there it could be “improved” or “simplified” (without implementing an interface) with the C# 3 syntax (lambda etc.) by the way.

  • 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-22T17:48:07+00:00Added an answer on May 22, 2026 at 5:48 pm
    private void button1_Click(object sender, EventArgs e)
    {
        this.Validators.ForEach(v => v.Validate());
    }
    

    or even:

    button1.Click += (sender, e) => { this.Validators.ForEach(v => v.Validate()); };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have user control that i wrote. this user control is appear on some
I have a user control and I want to create a property of type
I have a user control ( gallery.ascx ) and I want to use the
I want to have a User Control that takes a collection of People (property
I have a user control where the XAML of the control can bind to
This seemed easier in Web Forms; I'd have a user control, with the logic
I have a user control. It contrains LinkButton. I want to attach an click
I have a pretty simple user control that I want to bind a ScaleTransform
I have developed user control for ActiveX control in C# then register this component
I have a WPF user control that I want to print. I am able

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.