Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
CSS
I am using AjaxFileUploader to upload multiple files in my ASP.net project.

I want to validate RequiredFieldValidator on It, Means at least one file must be Upload before submit Form.

My Code is:


XML
<ajaxToolkit:AjaxFileUpload
    id="ajaxUpload1" ThrobberID="MyThrobber1" MaximumNumberOfFiles="5" runat="server" AllowedFileTypes="jpg,png"></ajaxToolkit:AjaxFileUpload>



How can validate this control as Requiredfiled, because Simple RequiredFieldValidator does not work on it.

is there any other solution ???
Posted
Comments
JoCodes 7-Dec-13 3:02am    
Have you tried HasFile property of fileuploader control?
Hitesh Vaghasiya 7-Dec-13 3:30am    
Yaaa... But i want to validate it to Client Side ...

is there any solution ???
JoCodes 7-Dec-13 3:46am    
Whats the current behaviour if using requiredfield on fileuploader?
Hitesh Vaghasiya 7-Dec-13 3:49am    
Its generate compile time error, RequiredFieldValidator does not support AjaxFileUpload controls ID

XML
Apply Below given Custom Validator on file Upload Control

<asp:CustomValidator CssClass="asterisk" ID="CustomValidator1" runat="server" Display="Dynamic" ControlToValidate="FileUploadCtrl" ErrorMessage="Please browse file to Upload"        SetFocusOnError="true" ValidateEmptyText="True" ValidationGroup="ValGrp"
                                        ClientValidationFunction="CheckFile">
</asp:CustomValidator>

Write below javascript
  function CheckFile(source, arguments) {

        var path = document.getElementById('<%= FileUploadCtrl.ClientID %>').value;
        if (path != "")
            arguments.IsValid = true;
        else
            arguments.IsValid = false;
    }


It will definitely help you
 
Share this answer
 
Comments
Hitesh Vaghasiya 7-Dec-13 6:57am    
Following Error Occured By this Code

Control 'FileUploadCtrl' referenced by the ControlToValidate property of 'CustomValidator1' cannot be validated.
madhuri@mumbai 7-Dec-13 7:10am    
just place your code here.
Wanna see your code.
you can try this code in java script.


var file= document.getElementById('AjaxFileUpload1.HasAttributes').value;
if(file==null)
{
alert('select your file');

}



more information place your code..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900