如何在ASP.net AjaxFileUploader中验证RequiredFieldValidator

问题描述:

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:







<ajaxToolkit:AjaxFileUpload

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







如何将此控件验证为Requiredfiled,因为Simple RequiredFieldValidator不起作用。



有没有其他解决方案???




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

is there any other solution ???

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


你可以尝试这个代码java脚本。





var file = document.getElementById('AjaxFileUpload1.HasAttributes')。value;

if( file == null)

{

alert('选择你的文件');



}







更多信息请输入您的代码..
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..