If else not working as expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mikejds2098
    New Member
    • Mar 2015
    • 2

    If else not working as expected

    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

    Code:
     If PasswordTextBox.Text = "" Then RadLabelError.Text = "Please Enter Your Password!"
            If PasswordTextBox.Text.Length < "8" Then
                RadLabelError.ForeColor = Color.Red
                RadLabelError.Text = "Password must be 8 Charecters!"
                RadDesktopAlert1.CaptionText = "Error"
                RadDesktopAlert1.ContentText = "Please Enter Your Password!"
                RadDesktopAlert1.Show()
                PasswordTextBox.Focus()
    
                PasswordTextBox.Clear()
    
                PasswordTextBoxValid = False
    
            Else
    
                PasswordTextBoxValid = True
                RadLabelError.Text = ""
    
            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
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    You need to nest your second If-Then statement within the the first one, under the Else part.
    Code:
     If PasswordTextBox.Text = "" Then 
        RadLabelError.Text = "Please Enter Your Password!"
    Else
        If PasswordTextBox.Text.Length < "8" Then
            RadLabelError.ForeColor = Color.Red
            RadLabelError.Text = "Password must be 8 Charecters!"
            RadDesktopAlert1.CaptionText = "Error"
            RadDesktopAlert1.ContentText = "Please Enter Your Password!"
            RadDesktopAlert1.Show()
            PasswordTextBox.Focus()
     
            PasswordTextBox.Clear()
     
            PasswordTextBoxValid = False
     
        Else
     
            PasswordTextBoxValid = True
            RadLabelError.Text = ""
     
        End If
    End If

    Comment

    Working...