I want to check the file size to prevent the large files to insert the database. I check the file with javascript but the message does not occur. Please check my code to where is wrong.
<script type="text/javascript">
function validateFileSize() {
var uploadControl = document.getElementById('<%= FileUpload1.ClientID %>');
var submit = document.getElementById("btnSubmit");
var browse = document.getElementById("FileUpload1");
if (uploadControl.files[0].size > 1048576){
document.getElementById('dvMsg').style.display = "block";
//return false;
submit.disabled = true;
browse.disabled = true;
}
else {
document.getElementById('dvMsg').style.display = "none";
//return true;
submit.disabled = false;
browse.disabled = false;
}
}
</script>
<div class="form-entry" align="center">
<div>
<h1>File Upload</h1>
<b>Select the file to upload:</b><br/>
<asp:Label ID="lblFileID" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:FileUpload ID="FileUpload1" AllowMultiple="true" runat="server" onchange="validateFileSize();"/>
<br/>
<div id="dvMsg" style="background-color:#006699; color:white; width:190px; padding:3px; display:none;" >
<br/>
Your choosing file size is big.
</div>
<asp:Button ID="btnSubmit" runat="server" Text="Save" OnClick="Upload" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click"/>
</div>