using asp.net required field validator with two check boxes - asp.net

i have two check boxes with male/female and i would like to add a required field validator for them so if none is checked then a custom error appears, i can already do this but with one control not two.
thanks

All I needed to do was instead of adding two separate CheckBoxs ,I needed to add a CheckBoxList:
CheckBoxList
and then use a normal RequiredFieldValidator on the CheckBoxList:
RequiredFieldValidator

You'll need to use the CustomValidator with a ClientValidationFunction
http://forums.asp.net/t/1402179.aspx
or -
You'll need to write a custom control or use one that's already made:
-http://www.codeproject.com/KB/validation/MultiDependValidator.aspx

Related

How do I check whether the controls in a usercontrol contain any value?

How do I check whether the controls in a usercontrol contain any value?
I have created a usercontrol called ctlCustomerAddress and I want to create an address record in the database if only I have the values in the textboxes.
There are number of ways to validate user input. You may use Validation Control (RequiredField), or write JavaScript code or write server side code to validate the user input.
You can use validation controls. Also write the save to DB code to a button inside the user control rather then the parent page ?
Is a RequiredValidator control what you're looking for? MSDN Reference.
You can also use CustomerValidator and RegularExpressionValidator controls.
Set their ValidationGroup properties to be the same as your submit button.

Required Field Validator For RadioButton Columns Inside Gridview

I have GridView and one columns is a RadioButton for select. How can I set a validator for columns to check that at least one RadioButton is selected?
I posted to a similar question the other day with a solution that should work for you:
How to check that at least one RadioButtonList has an item selected?
It uses a CustomValidator with a server side check to ensure at least one item is selected. You will need to substitute looking for a RadioButton instead of the RadioButtonList and maybe a few other tweeks but the code should work for what you need. It searchs for all of one type of control and checks for a specific critera. In your case look for all RadioButton controls and ensure at least one is checked.
there is no out-of-the-box way for what you are asking, you will need to use custom validator and implement the logic yourself on the client as well as on the server side; few way you can go about it, the one that comes to mind is to have the custom validator logic check at least one of the checkboxes is checked for passing IsValid, we will need more details about your structure to provide more specific solution

DDl compare validator

I had ddl and I added compare validator to make user choose from DDl.And I set all it,s properties well but when i forget to select ddl the validator apear well but when I selected from ddl The astrics(*) as error text it was still apear although I added it,s property focus on error=true.So please any one help me.
*
You should probably try to use another validator. It sounds like using the CustomValidator instead of the CompareValidator would be your way to go.
The asterix means that one of your validators says that your page is not valid. Try to set a breakpoint and determine which validator is not valid.

Using ASP.NET validators on multiple controls

can we use the same validator of a control for two different buttons,
or do we need to write add a validator for each control for two different buttons.
Each ASP.NET validator control can be bound to exactly one ControlToValidate, except for the CompareValidator. The CompareValidator also has a ControlToCompare property. You need to add a validator for each control you wish to validate.
When you find that your markup gets bloated with validators, you can also create a handy extension methods on Control and let it automaticaly add a new validator to the page. You can invoke this method in your code behind in OnPreInit or OnInit.

ASP .NET - Using RequiredFieldValidator when page has two listviews?

I have a page with two Listviews (with two different data sources). I have added RequiredFieldValidator controls to each of the InsertItemTemplate controls.
The first problem is that once all the validators were added they started requiring that both Listviews be populated before inserting. To fix this I tried to add different validation groups to the listviews but now the field validators don't work!
How do I get the Validators to work independently based on the Listview they are attached to?
Make sure both the ListViews and their respective RequiredFieldValidators have matching ValidationGroups.
Use the ValidationGroup attribute. Set the attribute to a different value for each relevant control in each ListView. For example, when a button is clicked with a ValidationGroup set, only the validators with a matching ValidationGroup are considered.

Resources