[Solved] Text box validation not working


I would change the following type of test:

if (txtFirstName.Text == "")

To:

if (string.IsNullOrWhiteSpace(txtFirstName.Text)) // .NET 4.0+

if (string.IsNullOrEmpty(txtFirstName.Text)) // .NET before 4.0

And for your additional test (no spaces allowed in the string):

if (string.IsNullOrWhiteSpace(txtFirstName.Text) && !txtFirstName.Text.Contains(" ")) // .NET 4.0+

if (string.IsNullOrEmpty(txtFirstName.Text) && !txtFirstName.Text.Contains(" ")) // .NET before 4.0

Note:

You will need to check that lblError.Text doesn’t contain anything in order to continue to the next page, as this is what holds your errors. I can only see the DateTime test, so even if any of your txt controls have failed the validation, you still transfer.

9

solved Text box validation not working