Skip to main content

Posts

Showing posts with the label change control's background color when validation fails

How to change control's background color when validation fails when controls have multiple validation

 Here Is the Code sample :   using System ; using System . Collections . Generic ; using System . Linq ; using System . Web ; using System . Web . UI ; using System . Web . UI . WebControls ; namespace ValidationHelper { public class ValidationBGColorAdjustor { public static void SetBGColor ( Page page ) { Dictionary < string , List > controls = new Dictionary < string , List >(); foreach ( BaseValidator validator in page . Validators ) { if ( controls . ContainsKey ( validator . ControlToValidate )) controls [ validator . ControlToValidate ]. Add ( validator . IsValid ); else controls [ validator . ControlToValidate ] = new List () { validator . IsValid }; } foreach ( string s in controls . Keys ) { bool IsValid = true ; ...

How to change control's background color when validation fails when controls have multiple validation

Here is the java script : function ContainsControl ( controlArray , arrayItem ) { var result = { boolValue : false , indexValue : - 1 }; for ( var i = 0 ; i < controlArray . length ; i ++) { if ( controlArray [ i ][ "control" ] == arrayItem . control ) { result . boolValue = true ; result . indexValue = i ; break ; } } return result ; } function SetBGColor () { var inputControlValidationResult = new Array (); for ( var i = 0 ; i < Page_Validators . length ; i ++) { var inputControl = document . getElementById ( Page_Validators [ i ]. controltovalidate ); var arrayItem = { control : inputControl , valid : Page_Validators [ i ]. isvalid ? 1 : 0 }; var result = ContainsControl ( inputControlValidationResult , arrayItem ); if ( result . boolValue ) { inputControlValidationResult [ re...