Required Field Validator fires when its enabled property set to true via javascript
I have a asp:dropdownlist, on its onchange event I have c开发者_JAVA技巧alled some javascript in which I'm enabling and disabling some required field validator, as soon as the RFV get enabled it displays the error msg attached to it..!!!!!!!!...
I want it only to be enable not to display the error msg at the time it gets enabled....
on submit click it should display the msg...
AND JAVASCRIPT :
function CriteriaChange(ddlCType)
{
switch (ddlCType.value)
{
case "1": //Weightage
ValidatorEnable(document.getElementById('<%= rfvWeightage1.ClientID %>'), true);
break;
case "2": //Any One
ValidatorEnable(document.getElementById('<%= rfvAppraiser.ClientID %>'), true);
break;
}
}
Since the visibility
CSS style is what gets toggled when the Validator is invoked for validation, you can just set this right after you enable your validator. The validation events would still be called again on submit, so it would overwrite this setting to show the validator when you want it, on form submit.
function CriteriaChange(ddlCType)
{
var val = null;
switch (ddlCType.value)
{
case "1": //Weightage
val = document.getElementById('<%= rfvWeightage1.ClientID %>');
break;
case "2": //Any One
val = document.getElementById('<%= rfvAppraiser.ClientID %>');
break;
}
if (val != null)
{
ValidatorEnable(val, true);
val.style.visibility = 'hidden'; // or collapse, if you prefer
}
}
Try this instead...
function CriteriaChange(ddlCType) {
switch (ddlCType.value)
{
case "1": //Weightage
// ValidatorEnable(document.getElementById('<%= rfvWeightage1.ClientID %>'), true);
document.getElementById('<%= rfvWeightage1.ClientID %>').enabled = true;
document.getElementById('<%= rfvAppraiser.ClientID %>').enabled = false;
break;
case "2": //Any One
//ValidatorEnable(document.getElementById('<%= rfvAppraiser.ClientID %>'), true);
document.getElementById('<%= rfvAppraiser.ClientID %>').enabled = true;
document.getElementById('<%= rfvWeightage1.ClientID %>').enabled = false;
break;
}
}
Note: I went ahead and had it disable the other validator in case they switch values back and forth so they don't both get enabled at the same time.
Hope this helps.
精彩评论