views:

838

answers:

3

I have a Required field validator attached to a fileupload control. When the user hits the insert button to insert the image into an html editor next to the control the validator fires off if nothing was in the fileupload text box. That works fine; however, when the save button at the bottom of the page is clicked it fires off the required validator if the fileupload control is empty. What i must I do so that validator can only fire off on the click of the insert button?

MORE POINTS IF THIS IS ANSWERED CORRECTLY:

What if I want a button to be apart of more than one validation group???

A: 

Is the ValidationGroup of the SaveButton the same as the validator? This would cause this error.

Matthew Jones
+1  A: 

Most controls have a boolean property called "CausesValidation". If you set this to false for controls that you wish to interact with without them firing the validators, it should solve the problem.

womp
This is a good answer.however, not exactly what i was looking for because I do want the Save button to validate, just not that fileupload control. Nevertheless +1.
Eric
+4  A: 

You could specify a validation group.

For example:

In your RequiredFieldValidator set ValidationGroup="Upload"

In your insert button specify the ValidationGroup to be Upload but don't specify a ValidationGroup on the Save button.

Emma Middlebrook
This is the best answer. Thanks. However, I had to specify a different validation group for the save button because if i didn't it still validated the fileupload.
Eric
+1 also. Thanks
Eric
There is another plus one if you can answer this....What if i want my button to be in two or more groups?
Eric
I'm not sure you can do that on the client side. Would you settle for a check on the server side? e.g.Page.Validate("Group1")Page.Validate("Group2")if (Page.IsValid) // continue as both groups passed
Emma Middlebrook