locked
How to validate mutually exclusive text boxes in C#.net RRS feed

  • Question

  • Hi,

    How to validate mutually exclusive text boxes in C#.net, but my text boxes are creating on runtime and number of text boxes are also vary from time to time. Can we use Ajax validators if yes how? or any other solutions exists pls. let me know?


    Vijay

    Friday, October 5, 2012 12:50 PM

Answers

  • this.Controls is an array which you can use to get all the controls on a form.  You can test the type of the control at run time by using the TYPE method.  An example of this is shown below.

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            List<Control> textboxes = new List<Control>();
            public Form1()
            {
                InitializeComponent();
                foreach (Control mytextbox in this.Controls)
                {
                    if (mytextbox.GetType() == typeof(TextBox))
                    {
                        textboxes.Add(mytextbox);
                    }
                }
            }
        }
    }


    jdweng

    • Marked as answer by Mike Feng Tuesday, October 9, 2012 10:58 AM
    Saturday, October 6, 2012 5:46 AM