Friday, 11 July 2014

Check uploaded file size in asp.net using javascript


//HTML

<asp:FileUpload ID="upl1" runat="server" onchange="CheckFileSize(this.id);" />

//SCRIPT

<script type="text/ecmascript">
 function CheckFileSize(upid) {
                var maxsize = 5 * 1024//1kb=1*1024
                var aspFileUpload = document.getElementById("" + upid + "");
                var filesze = aspFileUpload.files[0].size;
                if (filesze > maxsize) {
                    alert("Maximum file size is " + maxsize / (1024) + "KB");
                    return false;
                }
}

</script>

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...