Password as a null value

4 posts, 1 answers
  1. Andrew
    Andrew avatar
    26 posts
    Member since:
    Sep 2011

    Posted 17 Oct 2012 Link to this post

    If my viewmodel property for the password is null rather than an empty string the passwordbox throws an exception on binding. Shouldn't it treat as an empty string similar to other textboxes?

    Robert
  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 18 Oct 2012 Link to this post

    Hi Robert,

    Thank you for your question.

    Actually this exception is thrown when the native PasswordBox's Password value is set to null, and since we use it internally, you get the exception in RadPasswordBox as well. RadPasswordBox is made to be easy to import into existing project with the native PasswordBox and its behavior is like the PasswordBox rather that the textboxes, like the Password property opposed to the Text property in the textboxes.
    To avoid the exception, simply use string.Empty instead of null.

    Let me know if I can assist you further.

    Regards,
    Todor
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Andrew
    Andrew avatar
    26 posts
    Member since:
    Sep 2011

    Posted 18 Oct 2012 Link to this post

    The default passwordbox does not throw an exception or crash when I use null as my default value. However the telerik version does. It's easy to fix my making the default the empty string but I feel as though it should have the same behavior. Here is the exception data for your reference.

    Value can not be null.
    Parameter name: Password

       at System.Windows.Controls.PasswordBox.set_Password(String value)
       at Telerik.Windows.Controls.RadPasswordBox.OnPasswordChangedInternally(String newValue)
       at Telerik.Windows.Controls.RadPasswordBox.OnApplyTemplate()
       at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
       at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
       at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
       at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
       at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)

    Robert
  5. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 22 Oct 2012 Link to this post

    Hi Robert,

    It seems like the native PasswordBox throws the exception only if the Password property is set to null explicitly (see attached screenshots) and not when used with binding as you do in your scenario. However, this exception is not mentioned in the documentation for the PasswordBox, so probably the experience while using the control will be better without it. We will make sure that with our next internal build, expected by the end of the week, setting the Password in RadPasswordBox to null, will not throw an exception but will set the Password to string.Empty.

    Let me know if you have other suggestions or enquiries.

    All the best,
    Todor
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top