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.
Related
I have two buttons on my page and I want to trigger validator for only one of them not both.
first button is in masterpage.
second one in the page.
I do not want the first button trigger RequiredFieldValidator I set UseSubmitBehavior="False" button it does not work for me
Validation Groups allows to apply the validations for a group of controls. It works especially when there are multiple buttons on a page and if one button should trigger validations for set of controls and other button for another set. It can be achieved by setting validationgroup property to some string value on the validator controls along with button control.
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
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.
I have one asp content page.Its contain many controls like dropdownlist,textbox etc.All controls are inside a div tag.I gave required field validator for all my drop down list.i have one SAVE button that reside inside another div tag.I gave SAVE button cause validation true.But my problem is that, the validator is not working and the page.Isvalid property is true.What is the problem with my code?
Please make sure you have set the ControlToValidate property to the DropDownList id. Also you need to set the InitialValue property on the RequiredFieldValidator when validating a DropDownList. This basically just tells the Validator which item is the intial value (which will throw a validation error when it is selected).
Hope this helps,
Neil
I am using a telerik radgrid so there are around 5 columns each column edittemplate contains a control along with a required field validator and also a property called AllowMultiRowEdit is set to true so i am able to multiple rows in edit mode.
If any of the values are cleared the for multiple rows I want only those to be validated on update of that particular row.
So i implemented the Grids item data bound event find each and every validator along with the update button and set a unique validation group.
The above implementation most times but fails at some time. Is there any other way of going about this ?
You could use a customvalidator that uses code to check the other textboxes to ensure no value is being updated... requiredfieldvalidator always validates that a value has been supplied in the database, but CustomValidator gives you the ability to control the validation on the client and server. The issue becomes though, how to validate the other controls, and that will be tricky.
You will have to, from within the servervalidate or on the client, navigate up the control hierarchy from the validated control to the row level of the control and then find the other controls in the same row.