Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - RequiredFieldValidator to validate only particular controls

I have a web form. There are many different sections. I can say that each section displays data of a datatable. At each section I have OK and Cancel buttons. When I press OK any changes to the table in the database takes place. I've also put some Requiredfieldvalidators. Let's say I'm inserting a new record in the section one and the fields are correctly typed. When I press OK I get error message raised by the rest of the validators that are on the other sections. Isn't there any way that when I press OK button of a particular section to get validation errors of that same area? So what I probably need is a button that will not serve as the hole page submitter but rather a submitter of a specific section.

like image 723
Mikayil Abdullayev Avatar asked Apr 16 '12 06:04

Mikayil Abdullayev


2 Answers

Place a ValidationGroup on the RequiredFieldValidator's. Then place the same ValidationGroup on the correct submit button. When its clicked, only validation controls that are a part of the group are validated.

http://msdn.microsoft.com/en-us/library/ms227424.aspx

like image 138
janhartmann Avatar answered Sep 28 '22 04:09

janhartmann


I think janhartmann is correct ValidationGroup can help you solve the issue.Have a look at this article

like image 40
Priyank Patel Avatar answered Sep 28 '22 05:09

Priyank Patel