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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…