Last post Jun 11, 2009 09:49 PM by waveyus
Jun 06, 2006 01:09 PM|gabbyrozow|LINK
I have a textbox that has a regular expression validator on it.
I need to also add a conditional required validation on it. Meaning that a value is required only when a certain checkbox is checked.
I added an additional custom validator for the control and wrote a client-side function to check the value of the checkbox.
The problem is, that when the textbox is left blank, the custom validator does not run.
Jun 06, 2006 07:30 PM|fiXXXerMet|LINK
Jun 06, 2006 11:17 PM|plblum|LINK
Do not assign ControlToValidate on the CustomValidator. It will not know that the textbox is blank. Instead, your evaluation function must retrieve the value knowing the ClientID of the control. For example:
var val = document.getElementById('ClientID').value;
See this article for more on this an other common validation questions:
Jun 11, 2009 09:49 PM|waveyus|LINK
No need to have a cutom validator.
Just put your condition code under your normal RequiredFieldValidator Load event
protected void YourRequiredValidator_Load(object sender, EventArgs e)
YourRequiredValidator.Enabled = (yourcertaincheckbox.Checked)? true : false;
Also make your checkbox "AutoPostBack = true" if need.