Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 702125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:41:09+00:00 2026-05-14T03:41:09+00:00

I have a custom validation in the enterprise validation block. The DoValidate method is

  • 0

I have a custom validation in the enterprise validation block. The DoValidate method is as shown below.

protected override void DoValidate(Double objectToValidate, 
    object currentTarget, string key, ValidationResults validationResults)
{
    if (!IsSalMoreThanMinWage(objectToValidate))
    {
        //Here I need to mark this message as a "Warning"
        LogValidationResult(validationResults, 
            "Salary is too low for this state", currentTarget, key);
    }
}

I’d need to mark this validation failure as a “warning” message. In the front end, when I iterate through the ValidationResults collection and grab a ValidationResult object, I would need to identify and group different types of messages and render them differently.

My question is – how do I mark a failure as a warning?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:41:10+00:00Added an answer on May 14, 2026 at 3:41 am

    You can use the Tag property of the ValidationResult. “The meaning for a tag is determined by the client code consuming the ValidationResults.”

    If you are using configuration, then you can specify the tag in your configuration file:

    <validator lowerBound="0" lowerBoundType="Inclusive" 
    upperBound="255" upperBoundType="Inclusive" negated="false" messageTemplateResourceName="" messageTemplateResourceType="" 
    messageTemplate="Oops a warning occurred" 
    tag="Warning" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
    name="My Validator" />
    

    Or set the Tag with a property:

    [StringLengthValidator(5, 50, Ruleset = "RuleSetA", Tag="Warning")]
    

    If you want to do it programmatically, then you will have to create a new validation result since the Tag property is readonly:

    ValidationResults newResults = new ValidationResults();
    
    foreach (ValidationResult vr in validationResults)
    {
        newResults.AddResult( new ValidationResult( 
            vr.Message, vr.Target, vr.Key, "Warning", vr.Validator, vr.NestedValidationResults ) );
    }
    

    Then in the front end you can check the Tag property of the ValidationResult to see if it’s a warning:

    foreach (ValidationResult vr in validationResults)
    {
        if (string.Compare(vr.Tag, "Warning") == 0)
        {
            DisplayWarning(vr.Message);
        }
        else
        {
            DisplayError(vr.Message);
        }
    }
    

    Obviously, you can abstract this much better, aggregate the errors and warnings etc.

    UPDATE

    We don’t have identical requirements to yours but we do something similar. Unfortunately, the only way I know to execute the type of conditional validation you are talking about is to use RuleSets.

    What we do is use a naming convention for the RuleSets and construct the RuleSet Names at runtime. If the RuleSet exists then we run the validator. You could do something similar for your warnings. So you could have two RuleSets:

    • RuleSet_Salary_Update
    • RuleSet_Salary_Update_Warning

    And then retrieve a List of Validators based on whether you want to run the warning validation:

    public static List<Validator<T>> CreateValidators<T>(bool shoulIncludeWarning, RuleSetType rulesetType)
    {
         if (shouldIncludeWarning)
         {
             // Get warning validator if any
         }
    
         // Get Default validator (if any)
    }
    

    RuleSetType is an enum with different types of rules (e.g. Select, Insert, Update, Delete, PrimaryKey, etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 476k
  • Answers 476k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For a function you intend to call from jQuery instances,… May 16, 2026 at 4:48 am
  • Editorial Team
    Editorial Team added an answer Add the following into your root web.config <location path="." inheritInChildApplications="false"> May 16, 2026 at 4:48 am
  • Editorial Team
    Editorial Team added an answer It looks like you want parallel iteration. Simply do something… May 16, 2026 at 4:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.