C# ASP.NET文件大小验证程序未验证

C# ASP.NET文件大小验证程序未验证,c#,asp.net,validation,C#,Asp.net,Validation,因此,我的aspx文件中有几个ASP.NET文件上载控件- <asp:FileUpload ID="fulNature" class="form-control summer" runat="server" /><asp:Labe ID="lblNature" runat="server" Text="Label" Visible="false"></asp:Label> <asp:CustomValidator ID="CustomValidato

因此,我的aspx文件中有几个ASP.NET文件上载控件-

 <asp:FileUpload ID="fulNature" class="form-control summer" runat="server" /><asp:Labe ID="lblNature" runat="server" Text="Label" Visible="false"></asp:Label>
 <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="fulNature" Display="Dynamic"
                        ErrorMessage="File size should not be greater than 1 MB." ForeColor="#FF3300" OnServerValidate="ValidateFileSize"></asp:CustomValidator>

<asp:FileUpload ID="fulIndustrial" class="form-control summer" runat="server" /><asp:Label ID="lblIndustrial" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="fulIndustrial" Display="Dynamic"
                        ErrorMessage="File size should not be greater than 1 MB." ForeColor="#FF3300" OnServerValidate="ValidateFileSize"></asp:CustomValidator>
问题是,无论文件大小如何,验证器都不会启动。我必须在这里遗漏一些简单的东西,但我只是看不到而已。

试试:

long filesize = SubmittedUpload.FileContent.Length;

您可以直接获取上传文件的大小:

long size=fulNature.FileContent.Length;

它必须上传整个文件才能工作。我应该提到-文件上传器验证程序正被多个控件使用。我编辑了我的问题以反映这一点。这与6分钟前提交的答案有何不同?
long size=fulNature.FileContent.Length;