由自定义验证器验证的文件上传存在问题。文本框值始终为空或 null onververvalidate。
ASPX
<asp:CustomValidator ID="cvFileUpload" runat="server"
ErrorMessage="Please select file!" ControlToValidate="fuCheatingEvidence"
onservervalidate="cvFileUpload_ServerValidate"
ValidationGroup="vgSubmitForm" ValidateEmptyText="True"></asp:CustomValidator>
<asp:FileUpload ID="fuCheatingEvidence" runat="server"
Width="890px" Size="50" />
代码背后
protected void cvFileUpload_ServerValidate(object source, ServerValidateEventArgs args)
{
String fileName = fuCheatingEvidence.PostedFile.FileName;
if (fileName != "")
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
这只是检查 FileUpload 控件是否为空的简单检查,稍后我将添加更多自定义验证。