Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > BOOK: Silverlight 4 Problem - Design - Solution
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 4th, 2010, 11: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 01:15 AM.
Reply With Quote
  #2 (permalink)  
Old October 15th, 2010, 06: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 06:45 PM.
Reply With Quote
The Following User Says Thank You to Gabor66 For This Useful Post:
A. Bettik (February 7th, 2013)
  #3 (permalink)  
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;
          }
     }
}
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02:58 AM
Validate runtime generated text field trimba Classic ASP Basics 5 September 30th, 2004 10:19 AM
Update city field based on zip field nganb SQL Server ASP 0 April 22nd, 2004 11:30 PM
Validate calculated field in sub form MG76 Access 4 March 18th, 2004 04:26 PM



All times are GMT -4. The time now is 11:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.