This is a migrated thread and some comments may be shown as answers.

ValidationState not response properly

7 Answers 59 Views
PasswordBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
bento
Top achievements
Rank 2
bento asked on 23 Sep 2013, 09:42 AM
Hi,

I use these code but ValidationState text not response properly. When I type below 5 chars, text alert correctly, but more than that debug using breakpoint run well but text alert display still "Password too short". It should be, the next text but not shown. Can you try it ?

Thanks

private void textPassword_PasswordChanged(object sender, EventArgs e)
 {
     if (textPassword.Password.Length < 5)
     {
         isPasswordValid = false;
         textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Password too short!");
     }
     else if (!InputForm.IsPassword(textPassword.Password))
     {
         isPasswordValid = false;
         textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Use 1 uppercase, number & special char!");
     }
     else if (textPassword.Password.Length >= 5 && InputForm.IsPassword(textPassword.Password))
     {
         isPasswordValid = true;
         textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Valid, "");
     }
 }

7 Answers, 1 is accepted

Sort by
0
MasterChiefMasterChef
Top achievements
Rank 2
answered on 23 Sep 2013, 04:26 PM
Hi bento,

I would love to figure out why your PasswordBox is not vaidating correctly. Can you provide more code so that I can run your example? I would need the InputForm class so I can check your InputForm.IsPassword method. Let me know if this is possible!

Master Chief
0
Accepted
Todor
Telerik team
answered on 24 Sep 2013, 08:29 AM
Hi Benyamin,

Thank you for writing.

The reason for this behavior is that the method ChangeValidationState is expected to work to actually change the validation state which in your case is already Invalid and doesn't need changing. In order to be able to use the Invalid state with more than one message you need to change the validation state, before you check the password's length:

private void textPassword_PasswordChanged(object sender, EventArgs e)
{
 
    textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.NotValidated, string.Empty);
 
    if (textPassword.Password.Length < 5)
    ....
}

This way each time the text is changed the password box will be initially in the correct NotValidated state and you will be able to change it after you perform your validation.

Let us know if you need further assistance.
 
Regards,
Todor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
bento
Top achievements
Rank 2
answered on 24 Sep 2013, 09:31 AM
Hi Master Chief sorry for late reply, but thanks. 
Hi Todor, yes it is works.

Now I have new issue, sometimes screen freeze when Password and Retype Password events fired several times on textchanged. I'll post the code later. I need to recreate the sample first and test it on new project to make sure. Fyi I use Lumia 920 with Amber for device test. 
0
Todor
Telerik team
answered on 27 Sep 2013, 06:07 AM
Hi Benyamin,

If you confirm that there is an issue, don't hesitate to write back with more information. It would be best if you open a new support ticket to attach a project that we can use to reproduce your issue, since attachments are not permitted in forum posts.
 
Regards,
Todor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
bento
Top achievements
Rank 2
answered on 27 Sep 2013, 11:20 AM
Hi Todor,

I've created a copy portion of my code... here is... on my Lumia 920, please help to analyze and here the step :

  1. type a password any length on "Password" box (first box) 
  2. Press Peek Button to see password
  3. Screen freeze... Can press back button to hide keyboard, or use Win Button only.

<phone:PhoneApplicationPage x:Class="RadPasswordBox.MainPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:telerikPrimitives="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Primitives"
                            shell:SystemTray.IsVisible="True">
    <StackPanel x:Name="ContentPanel">
        <telerikPrimitives:RadPasswordBox Name="textPassword"
                                          Watermark="Password"
                                          BorderBrush="Peru"
                                          BorderThickness="0,0,1,2"
                                          MaxLength="25"
                                          PasswordChanged="textPassword_PasswordChanged" />
        <telerikPrimitives:RadPasswordBox Name="textRetypePassword"
                                          Watermark="Retype Password"
                                          BorderBrush="Peru"
                                          BorderThickness="0,0,1,2"
                                          MaxLength="25"
                                          PasswordChanged="textPassword_RetypePasswordChanged" />
    </StackPanel>
</phone:PhoneApplicationPage>


using System;
using Microsoft.Phone.Controls;
using RadPasswordBox.Resources;
namespace RadPasswordBox
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
        }
        private void textPassword_PasswordChanged(object sender, EventArgs e)
        {
            textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.NotValidated, string.Empty);
 
            if (textPassword.Password.Length < 5)
            {
                textPassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Password too short!");
            }
 
            if (textPassword.Password != textRetypePassword.Password)
            {
                textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.NotValidated, string.Empty);
                textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Password not match.");
            }
            else
            {
                textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.NotValidated, string.Empty);
                textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Valid, "");
            }
        }
        private void textPassword_RetypePasswordChanged(object sender, EventArgs e)
        {
            if (textRetypePassword.Password != textPassword.Password)
            {
                textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Invalid, "Password not match.");
            }
            else if (textRetypePassword.Password == textPassword.Password)
            {
                textRetypePassword.ChangeValidationState(Telerik.Windows.Controls.PhoneTextBox.ValidationState.Valid, "");
            }
        }
    }
}

0
Accepted
Todor
Telerik team
answered on 02 Oct 2013, 08:26 AM
Hi Benyamin,

This is a very strange issue which is related to the focusing of the elements. We will need more time to investigate it deeper and find a way to avoid the freeze. For now you can use the following workaround:

<StackPanel x:Name="ContentPanel">
    <ContentControl HorizontalContentAlignment="Stretch">
        <telerikPrimitives:RadPasswordBox Name="textPassword"
                                Watermark="Password"
                                BorderBrush="Peru"
                                BorderThickness="0,0,1,2"
                                MaxLength="25"
                                PasswordChanged="textPassword_PasswordChanged" />
    </ContentControl>
    <ContentControl HorizontalContentAlignment="Stretch">
        <telerikPrimitives:RadPasswordBox Name="textRetypePassword"
                                Watermark="Retype Password"
                                BorderBrush="Peru"
                                BorderThickness="0,0,1,2"
                                MaxLength="25"
                                PasswordChanged="textPassword_RetypePasswordChanged" />
    </ContentControl>
</StackPanel>

Simply place the password boxes inside content controls and the freeze will be avoided.
 
Regards,
Todor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
bento
Top achievements
Rank 2
answered on 02 Oct 2013, 01:39 PM
Thanks Todor, freeze is gone for now...
Tags
PasswordBox
Asked by
bento
Top achievements
Rank 2
Answers by
MasterChiefMasterChef
Top achievements
Rank 2
Todor
Telerik team
bento
Top achievements
Rank 2
Share this question
or