Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > BOOK: Silverlight 4 Problem - Design - Solution
| Search | Today's Posts | Mark Forums Read
BOOK: Silverlight 4 Problem - Design - Solution
This is the forum to discuss the Wrox book Silverlight 4 Problem - Design - Solution by Nick Lecrenski; ISBN: 9780470534045
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Silverlight 4 Problem - Design - Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2010, 10:02 PM
Authorized User
 
Join Date: Sep 2009
Posts: 34
Thanks: 4
Thanked 1 Time in 1 Post
Default UserRegistration doesn't validate ConfirmPassword field

For the confirm password field we created a Partial UserRegistration class on the client with the confirm_password property.

For the validation of this field we are using a custom validation attribute (UserInformationValidation.ValidateConfirmPassword ).

Unfortunately we get the error message only in the ValidationSummary of the Dataform control, and the error info doesn't appear aside the invalid field and the label doesn't became red.

If for localization purposes we delete the validationsummary of the dataform control (as I think this part of the control an overkill), the system validates the field, but the user will not be notified at all.

Does anybody solved this problem?

Thanks

Gabor

Last edited by Gabor66; October 5th, 2010 at 12:15 AM..
 
Old October 15th, 2010, 05:41 PM
Authorized User
 
Join Date: Sep 2009
Posts: 34
Thanks: 4
Thanked 1 Time in 1 Post
Default

I found the solution.

When WCF RIA services generates the code, attribute's validation is performed automatically, because the code for validation is implemented in the base Entity class.

If we create a partial class on the client with attributes, we have to force the system in the property setter to validate. For that purpose we have to use the Validator class static ValidateAttribute method:

Code:
        [Required]
        [Display (Name="ConfirmPassword")]
        [CustomValidation(typeof(UserInformationValidation), "ValidateConfirmPassword")]
        public string confirm_password
        {
            get
            {
                return confPswd;
            }
            set
            {
  
                ValidationContext context = new ValidationContext(this, null, null);
                context.MemberName = "confirm_password";

                Validator.ValidateProperty(value, context);

                confPswd = value;

                OnPropertyChanged(new PropertyChangedEventArgs("confirm_password"));
              }
          }
(Variable string confPswd declared at the class level)

Now the confirm_password validation works as any other attributes set on the server.

Thanks for read this

Gabor

Last edited by Gabor66; October 15th, 2010 at 05:45 PM..
The Following User Says Thank You to Gabor66 For This Useful Post:
A. Bettik (February 7th, 2013)
 
Old February 7th, 2013, 01:11 PM
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Gabor66.
I read that
Quote:
The PropertyChanged event is encapsulated in the RaiseDataMemberChanged(). You can check this with any Decompiler (.NET Reflector, etc.).
and the code below seems to work.


Code:
namespace fitnesstrackerplus.Web.Data
{
    public partial class UserInformation
    {
        private string confPswd;
        //Client side only, so need custom validation also.

        //public string confirm_password { get; set; } --doesn't work, so try below custom get and set and explicit field confPswrd
        [Required]
        [Display(Name = "Confirm Password:")]
        [CustomValidation(typeof(UserInformationValidation), "ValidateConfirmPassword")]
        public string confirm_password
        {
            get
            {
                return confPswd;
            }
            set
            {
                    ValidationContext context = new ValidationContext(this, null, null);
                    context.MemberName = "confirm_password";
                    Validator.ValidateProperty(value, context);
                    confPswd = value;
                    //OnPropertyChanged(new PropertyChangedEventArgs("confirm_password"));
                    this.RaiseDataMemberChanged("confirm_password");
            }
        }
    }

    public class UserInformationValidation
     {
          public static ValidationResult ValidateConfirmPassword(string confirm_password, ValidationContext context)
          {
               UserInformation current = context.ObjectInstance as UserInformation;

               if (current.password != confirm_password)
                    return new ValidationResult("Confirm password and password fields must be the same.");

               return null;
          }
     }
}




Similar Threads
Thread Thread Starter Forum Replies Last Post
how can validate dynamic textbox field & get data alpi Classic ASP Basics 0 November 4th, 2007 03:24 PM
Validate a Text Field zaeem VB Databases Basics 0 May 20th, 2005 01:58 AM
Validate runtime generated text field trimba Classic ASP Basics 5 September 30th, 2004 09:19 AM
Update city field based on zip field nganb SQL Server ASP 0 April 22nd, 2004 10:30 PM
Validate calculated field in sub form MG76 Access 4 March 18th, 2004 04:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.