requiredfieldvalidator

Conditionally required property using data annotations

余生长醉 提交于 2019-11-27 00:10:14
问题 I have a class like this: public class Document { public int DocumentType{get;set;} [Required] public string Name{get;set;} [Required] public string Name2{get;set;} } Now if I put a [Required] data annotation on the Name and Name2 properties, then everything is ok and if Name or Name2 are empty, validation will throw an error. But I want Name field only to be required if DocumentType is equal to 1 and Name2 only required if DocumentType is equal to 2 . public class Document { public int

Change Text Box Color using Required Field Validator. No Extender Controls Please

佐手、 提交于 2019-11-26 08:10:49
问题 I need to change color of TextBox whenever its required field validator is fired on Clicking the Submit button 回答1: What you can do is register a Javascript function that will iterate through the global Page_Validators array after submission and you can set the background appropriately. The nice thing about this is that you can use it on all of your controls on the page. The function looks like this: function fnOnUpdateValidators() { for (var i = 0; i < Page_Validators.length; i++) { var val