Nageshwar Rao

Nageshwar Rao

  • NA
  • 74
  • 34.9k

custom attribute to set string lenght dynamically

Sep 19 2016 11:34 AM
HI,
I want to set a string lenght for particular property by using custom attribute,i dnt want to set a constant string lenght
[Required(ErrorMessageResourceType = typeof(CampaignResource.VendorCampaign), ErrorMessageResourceName = "TitleRequired")]
[CustomValidation(typeof(VendorCampaignValidator), "ValidateName")]
[Display(Name = "Title", ResourceType = typeof(CampaignResource.VendorCampaign))]
public string Title { get; set; }///
public class VendorCampaignValidator : ValidationAttribute
{
public static ValidationResult ValidateName(string campaignName)
{
ResourceManager rm = new ResourceManager(typeof(InQuest.Sax.Resources.VendorCampaign));
if (string.IsNullOrWhiteSpace(campaignName))
return new ValidationResult(rm.GetString("TitleRequired"));
if (campaignName.Length <= VendorCampaignSettings.NameMaxLength)
{
return ValidationResult.Success;
}
else
{
return new ValidationResult(rm.GetString("InvalidLengthTitle"));
// return new ValidationResult(rm.GetString("Title should be at most 25 characters long"));
}
I am taking value from web.config file but it is not working

Answers (1)