jQuery Multi File上传禁用上传按钮

时间:2012-11-12 16:05:19

标签: jquery asp.net multifile

我正在尝试使用jQuery Multiple File Upload,但验证时遇到问题。我的验证运行后,文件上传控件被禁用,我无法弄清楚原因。我在这里重新创建了最低限度以证明问题。

<%@ Page Language="C#" AutoEventWireup="true"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<script language="c#" runat="server">
    protected void validate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = false;
    }
</script>
<head runat="server">
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery.MultiFile.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        function validate(sender, args)
        {
            args.IsValid = false;
            //addedd as suggested on the following, but it doesn't work
            //fyneworks.com/jquery/multiple-file-upload/#tab-Uploading
            $.fn.MultiFile.reEnableEmpty();  
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:FileUpload ID="attachments" runat="server" class="multi"  />
        <asp:CustomValidator runat="server" ID="customValidator" 
                             ErrorMessage="This field is required" 
                             OnServerValidate="validate"
                             ClientValidationFunction="validate" />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Submit" />
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我弄清楚如何解决这个问题的唯一方法是手动重新启用按钮。 我添加了超时,以确保在我的代码运行之前一切都已完成。

setTimeout(function () { $(questionNode).find('> .answer > div > .MultiFile-wrap > .multi').removeAttr('disabled');}, 200);