Use custom validator as follow :-
<asp:CustomValidator ID="NewPasswordCustomValidator" runat="server" Text="File Size Limit exceed !! Only 20 MB is allowed"
ToolTip="FileSize should not exceed 4 MB" ControlToValidate="FileUpload1" ClientValidationFunction="setUplaodButtonState"
Display="Dynamic" ValidationGroup="submit" ErrorMessage="File Size Limit exceed !! Only 20 MB is allowed"></asp:CustomValidator>
Then make one javascript function to put limit on size upto 20mb
function setUplaodButtonState(oSrc, args) {
var maxFileSize = 20480000 // 20MB -> 20000 * 1024 //
var fileUplaod = $("#<%=FileUpload1.ClientID %>");
if (fileUplaod.val() == '') {
args.IsValid = false;
}
else {
if (fileUplaod[0].files[0].size < maxFileSize) {
args.IsValid = true;
} else {
alert('File Size is' + ((fileUplaod[0].files[0].size / 1000) / 1024).toFixed(2) + 'MB !! Only size upto 20 MB is allowed');
args.IsValid = false;
}
}
}
<asp:CustomValidator ID="NewPasswordCustomValidator" runat="server" Text="File Size Limit exceed !! Only 20 MB is allowed"
ToolTip="FileSize should not exceed 4 MB" ControlToValidate="FileUpload1" ClientValidationFunction="setUplaodButtonState"
Display="Dynamic" ValidationGroup="submit" ErrorMessage="File Size Limit exceed !! Only 20 MB is allowed"></asp:CustomValidator>
Then make one javascript function to put limit on size upto 20mb
function setUplaodButtonState(oSrc, args) {
var maxFileSize = 20480000 // 20MB -> 20000 * 1024 //
var fileUplaod = $("#<%=FileUpload1.ClientID %>");
if (fileUplaod.val() == '') {
args.IsValid = false;
}
else {
if (fileUplaod[0].files[0].size < maxFileSize) {
args.IsValid = true;
} else {
alert('File Size is' + ((fileUplaod[0].files[0].size / 1000) / 1024).toFixed(2) + 'MB !! Only size upto 20 MB is allowed');
args.IsValid = false;
}
}
}
Comments
Post a Comment