javascript:

var OriginalValidatorUpdateDisplay = null;
function NewValidatorUpdateDisplay(val) {

OriginalValidatorUpdateDisplay(val);
if (val.controltovalidate) {
if (!CheckValidatorsForControl(document.getElementById(val.controltovalidate))) {
if (document.getElementById(val.controltovalidate).toString() == “[object HTMLSelectElement]“)
document.getElementById(val.controltovalidate).style.backgroundColor = “#FFAAAA”;
else
document.getElementById(val.controltovalidate).style.background = “#FFAAAA”;
}
else {
if (document.getElementById(val.controltovalidate).toString() == “[object HTMLSelectElement]“)
document.getElementById(val.controltovalidate).style.backgroundColor = “”;
else
document.getElementById(val.controltovalidate).style.background = “#FCFCFC”;
}
}
}

if (typeof (ValidatorUpdateDisplay) == ‘function’) {
OriginalValidatorUpdateDisplay = ValidatorUpdateDisplay;
ValidatorUpdateDisplay = NewValidatorUpdateDisplay;
}

function CheckValidatorsForControl(control) {
for (var i = 0; i < control.Validators.length; i++) {
if (!control.Validators[i].isvalid) {
return false;
}
}
return true;
}

function fnOnUpdateValidators() {
for (var i = 0; i < Page_Validators.length; i++) {

var val = Page_Validators[i];
var ctrl = document.getElementById(val.controltovalidate);

if (ctrl != null && ctrl.style != null) {

if (!val.isvalid) {
if (ctrl.toString() == “[object HTMLSelectElement]“)
ctrl.style.backgroundColor = “#FFAAAA”;
else
ctrl.style.background = “#FFAAAA”;
}
else {
if (ctrl.toString() == “[object HTMLSelectElement]“)
ctrl.style.backgroundColor = “”;
else
ctrl.style.background = “#FCFCFC”;
}
}
}
}

C# code :

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), “val”, “fnOnUpdateValidators();”);
}

Advertisements