如何在ASP.net AjaxFileUploader中验证RequiredFieldValidator [英] How to validate RequiredFieldValidator in ASP.net AjaxFileUploader

查看:61
本文介绍了如何在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..


这篇关于如何在ASP.net AjaxFileUploader中验证RequiredFieldValidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆