Required Field Validator + AsyncFileUpload
I have been trying to apply the default ASP.Net Required Field Validator to an AsyncFileUpload control (from the AJAX Control Toolkit).
The Scenario
I have created a Web User Control. Let’s call it wucFileUpload.
wucFileUpload has an AJAX Update Panel that is wrapping the Required Field Validator and the AsyncFileUp开发者_JAVA技巧load. (I have to use the AJAX Update Panel for some particular reasons).
wucFileUpload is going to be used in many pages, and in some of them, this control is going to be generated automatically, so I do not know how many of them I will have per page.
wucFileUpload has a property called Required. If Required is true, it will enable the Required Field Validator, to check if the AsyncFileUpload has been filled at least once.
My try
I found this solution here on StackOverflow, and I tried to apply it. However, my case is a little bit different, from the one represented on that question.
My thoughts
I really liked the idea of having a hidden Textbox or a HiddenField. Because a single AsyncFileUpload can upload N number of files.
The Textbox could get some value on the first time OnClientUploadComplete runs… this way I’ll know the user has uploaded at least one image.
But I would also need a way of clearing that Textbox, because the user can delete the image that he just uploaded. And if the does that, then the field must be validated again.
精彩评论