Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validate field if checkbox.checked 2

Status
Not open for further replies.

devRyan

Programmer
Sep 1, 2006
104
US
Hi all,

I was wondering how to require a text field on the condition that a checkbox is checked.

I have a text field that collects a completion date with a related checkbox that denotes isComplete. I want to set a requiredField validator on the text field.

I've added a required field validator to the text field and set it to enabled=false, and in the code behind when I confirm that the check box is checked, I set the requiredField validator to enabled=true, then call the validate function for the validator, like so:

if (checkbox.chacked)
{
this.reqValDateCompleted = true;
this.reqValDateCompleted.Validate();
}

but nothing happens, which makes me think I'm using the wrong methods for doing this.

Can someone point me in the right direction, please?
 
It just doesn't seeem to be getting the object through the master pages.

I've added an if statement that checks to see if the object is null, and it returns as such, which I pretty much already knew because the NullReferenceException. Now the question is: "Why is it not passing the object reference through the master page?
 
Why are you using FindControl to get a reference to the control?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
It was suggested, and I don't know any better. What else should I try?
 
Ok, well problem solv-ed.

Upon the questioning of using the FindControl method, I put the code back to what I originally posted as not working and it now runs fine. I'm relieved and aggrevated all at once.

Thank you both for being so patient and helpful.
 
OK, glad it's sorted. Not sure why FindControl was suggested though - that's only needed if you need to find a control from a parent container and in your case, you didn't have one. For more info see:



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top