javascript - How to ensure the selected file count to be either zero or one using javasript -


in application have edit button in gridview user click edit button , when clicks edit button data related particular edited row gets binded corresponding textboxes , fileupload controls @ case user may select file or may not select file if selected count of files should not greater 1 or 0 how can below fileupload contol,update button , edit image code

<asp:fileupload id="filuploadmp3" runat="server" width="224px" multiple="multiple" onchange="javascript:return checkwavextension();"  /> <asp:button id="btnupdate" runat="server" onclick="btnupdate_click" text="update" width="62px" onclientclick="return validatestuff();" /> <asp:imagebutton id="btn1" runat="server" text="edit" commandname="mybutton" width="20px" imageurl="~/images/page_white_edit.png" tooltip="edit" /> 

to allow 1 file select remove multiple="multiple" fileupload

<asp:fileupload id="filuploadmp3" runat="server" width="224px"  onchange="javascript:return checkwavextension();"  /> 

or if want have can check count like

function validatefile(){     var filecount = document.getelementbyid('filuploadmp3').files.length;     if(filecount > 1) // selected images in 1count     {        alert("please select 1!!");        return false;     }     else if(filecount <= 0) // selected atleast 1      {        alert("please select atleat 1!!");        return false;     }      return true;  // go }      function checkwavextension() {     var chkfile = document.getelementbyid('<%= filuploadmp3.clientid %>');     var label = document.getelementbyid('<%= lblerrmsg.clientid%>');     var myfile = chkfile.value;     if (myfile.indexof(".wav") > 0 || myfile.indexof(".mp3") > 0) {         label.innertext = "valid format";       //check mode insert or update       //if update        return validatefile();     } else {         label.innertext = "invalid format";         chkfile.value = "";     } }  function validatefile(){     var filecount = document.getelementbyid('filuploadmp3').files.length;     if(filecount > 1) // selected images in 1count     {        alert("please select 1!!");        return false;     }     else if(filecount <= 0) // selected atleast 1      {        alert("please select atleat 1!!");        return false;     }      return true;  // go } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -