I want to make my custom javascript validator client function generic and I’m having trouble obtaining the ControlToValidate ID in my function for the user control.
The user control is in a asp:wizard control in a modal popup which is in a page and the whole she-bang uses a master page. I don’t know if this information matters.
The following js code works for validation on the user control which is basically a dropdown list. Getting the ID of a single specific control isn’t generic at all.
function checkCombo(sender, args) {
var cb = document.getElementById('<%= cmbList.ClientID %>_cmbList');
args.IsValid = (cb.options[cb.selectedIndex].text != '-- Select --');
}
What is supposed to work, doesn’t (sender.ControlToValidate). I need to be able to use one function on about 20 different dropdown list user controls.
var cb = document.getElementById(sender.controltovalidate);
How can I get this control ID in a generic fashion so that my custom javascript validation function will work on all of these user control dropdowns?
Thanks!
–Bob
You can get the control value from args without knowing the control itself:
This will work if you set the value of the option “– Select –” to -1.
Anyway, I think you can achieve that with a
RangeValidatorlike in here https://stackoverflow.com/a/5116098/1495902