Efficient way to check if all textboxes are not empty

asp.net, vb.net

Solution

You should use multiple `RequiredFieldValidators` with a common `ValidationGroup`.

However, if you really want to go this way you could use `Linq`. Assuming all TextBoxes are in the same container control, for example a `Panel` called `FormPanel`:

Dim emptyTextBoxes = From txt In FormPanel.Controls.OfType(Of TextBox)()
                     Where String.IsNullOrEmpty(txt.Text)
If Not emptyTextBoxes.Any() Then
    ' ...
End If

Problem

I want to check if all the textboxes are filled before submitting the form, the way I'm doing this atm is like this: ``` If strGebruikersnaam <> String.Empty And strVoornaam <> String.Empty And strFamilienaam <> String.Empty And strEmail <> String.Empty And strBevestigEmail <> String.Empty And strWachtwoord <> String.Empty And strBevestigWachtwoord <> String.Empty And strAntispam <> String.Empty Then End If ``` I would like to know if there is an more efficient way to do the same thing.

Original source