Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to pass id as a parameter of FileUpload to javascript function to check extension and size of file
    text
    copied!<p>I am working on asp.net web application in which i have 6 FileUpload Controls for one file upload i have created a javascript method to check file extension and file size. but how to pass id of FileUpload upload dynamically so that only in only one method i can validate all FileUpload my code of javacript is </p> <pre><code> var validFilesTypes = ["bmp", "gif", "png", "jpg", "jpeg", "doc", "docx", "xls", "xlsx", "htm", "html", "rar", "zip", "txt", "pdf"]; function CheckExtension() { /*global document: false */ var file = document.getElementById("&lt;%=txtTenderDoc.ClientID%&gt;"); var path = file.value; var ext = path.substring(path.lastIndexOf(".") + 1, path.length).toLowerCase(); var isValidFile = false; for (var i = 0; i &lt; validFilesTypes.length; i++) { if (ext == validFilesTypes[i]) { isValidFile = true; break; } } if (!isValidFile) { alert("Invalid File. Unknown Extension Of Tender Doc" + "Valid extensions are:\n\n" + validFilesTypes.join(", ")); } return isValidFile; } function validateFileSize() { /*global document: false */ var file = document.getElementById("&lt;%=txtTenderDoc.ClientID%&gt;"); var fileSize = file.files[0].size; var isValidFile = false; if (fileSize !== 0 &amp;&amp; fileSize &lt;= 25214400) { isValidFile = true; } if (!isValidFile) { alert("File Size Should be Greater than 0 and less than 25 mb"); } return isValidFile; } </code></pre> <p>and i have used this in aspx page</p> <pre><code>&lt;asp:FileUpload ID="txtTenderDoc" onchange="var result= CheckExtension();validateFileSize(); return result" runat="server"&gt;&lt;/asp:FileUpload&gt; </code></pre> <p>as you can see i have to create <strong>6 method</strong> by this to check file size and file extension how to do that in only one method....</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload