Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
hi to all,
Here i want to do validate two textbox in partialviews.

DESCRIPTION:
In my model entities i have only password field but in Partialviews i have two text-box one is password and confirm password. i just compare and validate only in partialviews .If its correct then password should be store in database. In partialview i'm using @HTML
Posted
Updated 4-Aug-14 2:10am
v2

<asp:comparevalidator runat="server" id="Comp1" controltovalidate="Tconfirmpassword" controltocompare="Tpassword" text="Password mismatch" font-bold="true" xmlns:asp="#unknown">

Try this !!
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 4-Aug-14 8:10am    
Here im using mvc and html. so kindly tell about html code
Just to throw a different solution into the mix, I'd recommend ditching the built-in model validation and giving FluentValidation a go.

https://fluentvalidation.codeplex.com/[^]

It's much more flexible and you can use built-in rules, create your own custom rules and even set rules to be conditional.

From their website:

public class CustomerValidator: AbstractValidator<customer> {
    public CustomerValidator() {
        RuleFor(customer => customer.Surname).NotEmpty();
        RuleFor(customer => customer.Forename).NotEmpty().WithMessage("Please specify a first name");
        RuleFor(customer => customer.Discount).NotEqual(0).When(customer => customer.HasDiscount);
        RuleFor(customer => customer.Address).Length(20, 250);
        RuleFor(customer => customer.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode");
    }

    private bool BeAValidPostcode(string postcode) {
        // custom postcode validating logic goes here
    }
}

Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();
ValidationResult results = validator.Validate(customer);

bool validationSucceeded = results.IsValid;
IList<validationfailure> failures = results.Errors;</validationfailure></customer>
 
Share this answer
 
C#
[NotMapped]//dummy values not affect database
     [Compare("User_Password")]
     public string Confirm_Password { get; set; }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900