By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

If else not working as expected

P: 2
Hi I know it is something simple but I cant get the if else to work as expected

this is the code i am using

Expand|Select|Wrap|Line Numbers
  1.  If PasswordTextBox.Text = "" Then RadLabelError.Text = "Please Enter Your Password!"
  2.         If PasswordTextBox.Text.Length < "8" Then
  3.             RadLabelError.ForeColor = Color.Red
  4.             RadLabelError.Text = "Password must be 8 Charecters!"
  5.             RadDesktopAlert1.CaptionText = "Error"
  6.             RadDesktopAlert1.ContentText = "Please Enter Your Password!"
  7.             RadDesktopAlert1.Show()
  8.             PasswordTextBox.Focus()
  9.  
  10.             PasswordTextBox.Clear()
  11.  
  12.             PasswordTextBoxValid = False
  13.  
  14.         Else
  15.  
  16.             PasswordTextBoxValid = True
  17.             RadLabelError.Text = ""
  18.  
  19.         End If
I would like it to test two things is the password is empty display a msg or if it is less than 8 chars display a msg

thanks

MJ
Mar 29 '15 #1
Share this Question
Share on Google+
1 Reply


Seth Schrock
Expert 2.5K+
P: 2,932
You need to nest your second If-Then statement within the the first one, under the Else part.
Expand|Select|Wrap|Line Numbers
  1.  If PasswordTextBox.Text = "" Then 
  2.     RadLabelError.Text = "Please Enter Your Password!"
  3. Else
  4.     If PasswordTextBox.Text.Length < "8" Then
  5.         RadLabelError.ForeColor = Color.Red
  6.         RadLabelError.Text = "Password must be 8 Charecters!"
  7.         RadDesktopAlert1.CaptionText = "Error"
  8.         RadDesktopAlert1.ContentText = "Please Enter Your Password!"
  9.         RadDesktopAlert1.Show()
  10.         PasswordTextBox.Focus()
  11.  
  12.         PasswordTextBox.Clear()
  13.  
  14.         PasswordTextBoxValid = False
  15.  
  16.     Else
  17.  
  18.         PasswordTextBoxValid = True
  19.         RadLabelError.Text = ""
  20.  
  21.     End If
  22. End If
Jun 5 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.