Required Field Validator Use

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to use a required field validator and have it make a user
answer a comment field based on a drop down value picked? For instance, if
the user selects "It was terrible", make them have to enter comments before
allowing that page to be submitted.

If that cannot be done, what is the best way to do this. What makes it
harder is that the questions are being placed on the form from a database
dynamically, so we cannot write any java code ahead of time.

Any replies would be greatly appreciated.
 
1)Enable your DropDownList Control for AutoPostBack
2)Implement SelectedIndexChanged Event so thet you Enable or Disable your
Required Field Validator according to the value selected from the DropDownList
for example:

if(cmb.SelectedValue =="YourValue")
{
RequiredFieldValidator1.Enabled = true;
}
else
{
RequiredFieldValidator1.Enabled = false;

}
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
 
Thanks...I will look at your solution.

I am actually hoping to do this client side. I believe I have a good
solution I am coding. I will add an attribute to the dropdown that runs a
java script that takes in the dropdown object, the object that needs
validation, and the values of the dropdown that will cause the validation to
be enabled. Then I will check to see if the dropdown value selected is one
that I will be looking for and then validate the object then. I will then
attempt to attach this to the page submit event.

Thanks for your response though...I did not think of having the dropdown
post back.
 
You should use CustomValidator for this purpose. A RequiredFieldValidator
will not work on conditional basis. That is how it was in .net 1.1.. I am
not sure if it has changed the way it works in asp.net 2.0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top