Disable Button based on file size using JavaScript in ASP.Net

Last Reply one year ago By onais

Posted one year ago

Check File size and if in range upload the file not in range disable upload button

on single webform it work perfectlly when i put it in my content page which is linked to master page not diasbling the button

<script type="text/javascript">
function validateFileSize() {
var uploadControl = document.getElementById('<%= FileUpload1.ClientID %>');
if (uploadControl.files[0].size > 1048576) {
alert('1');
document.getElementById('dvMsg').style.display = "block";
document.getElementById("btnUpload").disabled = true;
alert('2');
return false;
alert('3');
}
else {
document.getElementById('dvMsg').style.display = "none";
document.getElementById("btnUpload").disabled = false;
return true;
}
}
</script>

 

<asp:FileUpload ID="FileUpload1" runat="server" onchange="validateFileSize();" />
<asp:Button ID="btnUpload" Text="Upload File" runat="server" 
    name="submit" value="Submit" OnClientClick="return checkfile();"
    onclick="btnUpload_Click" />

 

You are viewing reply posted by: onais one year ago.
Posted one year ago

 

<script type="text/javascript">
function validateFileSize() {
var uploadControl = document.getElementById('<%= FileUpload1.ClientID %>');
if (uploadControl.files[0].size > 1048576) {
alert('1');
document.getElementById('dvMsg').style.display = "block";
document.getElementById("<%=btnUpload.ClientID%>").disabled = true;
// document.getElementById("btnUpload").disabled = true;
return false;

}
else {
document.getElementById('dvMsg').style.display = "none";
document.getElementById("<%=btnUpload.ClientID%>").disabled = false;
return true;
}
}
</script>