<Asp:fileuploadID= "FileUpload1"runat= "Server"onchange= "chgimg (this)" /> <Div> <imgsrc=""ID= "Photo"runat= "Server"style= "Max-height:80px;float:left" /> <DivID= "Preview"></Div> </Div>
foreground control and code
functionchgimg (file) {//img Control preview Picture //var FileUpload1 = $ ("#FileUpload1"). Val (); //div preview Picture (compatibility mode)$ ("#ContentPlaceHolder1_Photo"). attr ("src", "" "); varPrevdiv = document.getElementById (' preview '); if(File.files && File.files[0]) { varReader =NewFileReader (); Reader.onload=function(evt) {prevdiv.innerhtml= ' ; } reader.readasdataurl (file.files[0]); } Else{prevdiv.innerhtml= ' <div class= ' img "style=" Max-height:80px;filter:progid:dximagetransform.microsoft.alphaimageloader ( Sizingmethod=scale,src=\ ' + file.value + ' \ ') ' ></div> '; } }
FileUpload Implement upload preview function