I have three upload buttons in my asp.net form and I am using asp.net validation control. I want user to upload anyone of those files. I can do it with jquery but please tell me how to achieve it by using Asp.Net validation controls. Thank you.
1 Answers
You need to use validation groups
, see https://msdn.microsoft.com/en-us/library/ms227424(v=vs.140).aspx for specifics.
Essentially you'll have your upload button:
<asp:FileUpload runat="server" ID="fu1" ... />
Then your required field validator:
<asp:RequiredFieldValidator ID="vldFu1" runat="server"
ControlToValidate="fu1" ValidationGroup="fuGroup1" ... />
And your button:
<asp:Button runat="server" ID="cmdFu1" ValidationGroup="fuGroup1" ... />
That way, your controls will use separate validations limited to each group, and they'll not interfere with each other.
As you say, you can use JavaScript to enable and disable validators - See here for details on this:Enable/Disable asp:validators using jquery
EDIT TO ADD
If you need to have at least one of the three completed, you'll need a customValidator
, there's a number of answer already on SO with the details:
asp.net required field validator for at least one textbox contains text
Using validators to ensure that user filled either one of two required fields
asp.net validate textbox - at least one text box must have data in
If you would like specific help, please post code examples and specific errors / problems

- 1
- 1

- 11,639
- 7
- 37
- 56
-
But I have many other fields also and one submit button only so I can not afford to use one button for that specific ValidationGroup. – Vivek Mishra Feb 05 '15 at 09:42
-
Ah, So you're actually asking that "any one" of the three `File Upload` controls needs to be complete, in which case you'll need to make your own `customValidator`, see the edit – RemarkLima Feb 05 '15 at 18:03
-
1Thank you so much for the links. You solved my problem. – Vivek Mishra Feb 06 '15 at 06:13