Within the single form it is evident that you can have multiple validation groups. To explain more, it is good to throw some light on such requirement. In our current project we have the following requirement.
If you observe this screenshot, the “Request a Quote” box is repeated. And on click of “Add More” button, one more “Request a Quote” would be added to the screen. Every time such a box is added, they are generated along with RequiredFieldValidator and adding the ValidationGroup property with the respective item index. In the above case, we have 2 validation groups. Now the problem is about validating the required fields on “Submit” button.
If there is only one validation group, you can directly associate the validation group to button with the “ValidationGroup” property. But in this case, we don’t a direct association of single validation group with single button. Hence we need to associate the multiple groups with the submit button, as mentioned below
<asp:Button ID="btnSave3" runat="server" ValidationGroup="3" Text="Submit" OnClick="btnSave3_Click" />
The latest .NET Framework v3.5 doesn’t support the multiple ValidationGroups association before submitting the page to server. Here is the information about such feature unavailability. As it is a limitation with .net framework, started exploring the alternatives.
Got many articles, to resolve this situation. Javi on his one of the old posts, mentioned a JQuery mechanism along with a custom button control. Brain Main’s blog has similar post. Many more if you bing.. What every they are, they all look at the simple Validate() method of Page class. Instead of investing my time again & again and reinventing the same wheel, i decided to go as simple as possible of using Page.Validate and verify that the Page.IsValid property to decide to proceed with the consecutive commends execution. Code looks like the below
// Means there is no Error with the data as well as Required fields
string strIPData = CollectPreviousItem();
// Invoke the Bussiness Method
Do you have any other possibility??
(ofcourse, you would not.. but just checking if some thing unearthed would see light)