Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.. is there any one who can help me.
i have a problem with required field validator. actually i have a registration form and there are some fields like(full name. last name , d.o.b, etc).
there is a check box and what i want that when i check that checkbox the required validator that i have applied on full name or last name visiblity will be hidden. i mean will not work. and rest of all required field validator will work.pls help me out..
Posted
Comments
AshishChaudha 4-Oct-12 0:27am    
have you tried anything????

First check for validation group...
check for Display="None" in required field.
 
Share this answer
 
Hi,
Go to the checked changed event of your checkbox and disable the RequireFieldValidator(make sure the AutoPostBack property of your CheckBox is set to true). Try this:
C#
protected void checbox1_CheckChanged(object sender, EventArgs e)
{
    if(checkbox1.Checked)
    {
        //Suppose your first name RequiredFieldValidator's id is RequiredFieldValidator1
        //And your last name RequiredFieldValidator's id is RequiredFieldValidator2
        RequiredFieldValidator1.Visible = false;
        RequiredFieldValidator2.Visible = false;
    }
    else
    {
        RequiredFieldValidator1.Visible = false;
        RequiredFieldValidator2.Visible = false;
    }
}




--Amit
 
Share this answer
 
Hi

There is another solution you can try (if you want to make this all in client side ) with custom validator. In the validation function you can check if the check box is checked or not and then check your field based on the check.

Please see the link and go to "Custom Validator" Section

http://msdn.microsoft.com/en-us/library/aa479013.aspx[^]

Hope this will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900