I have seen many people on the internet asking how to use fileupload before uploading, preview the image first, the prerequisites, and do not allow uploading to the server first! Most of the methods to implement the search results are uploaded to the server first, and then displayed. If you are not sure about the upload, delete it. This is too risky and consumes a lot of performance! The followingCodeWe don't need to upload the image to the server to preview it. Is it cool! Don't talk about it. Go to the code!
Code
<% @ Page Language = " C # " %>
<!Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ScriptRunat= "Server">
</Script>
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head ID = "Head1" Runat = "Server" >
< Title > Preview image in fileupload </ Title >
< Style Type = "Text/CSS" >
# Newpreview
{
Filter : Progid: DXImageTransform. Microsoft. alphaimageloader (sizingmethod = scale) ;
}
</ Style >
</ Head >
< Body >
< Script Language = "JavaScript" Type = "Text/JavaScript" >
Function Previewimg (imgfile)
{
VaR Newpreview = Document. getelementbyid ( " Newpreview " );
Newpreview. Filters. Item ( " DXImageTransform. Microsoft. alphaimageloader " ). SRC = Imgfile. value;
Newpreview. style. Width = " 80px " ;
Newpreview. style. Height = " 60px " ;
}
</Script>
< Form ID = "Form2" Runat = "Server" >
< Div >
< ASP: fileupload ID = "Fileupload1" Runat = "Server" Onchange = "Previewimg (this )" />
</ Div >
< Div ID = "Newpreview" >
</ Div >
< Input Type = "File" Onchange = "Document. getelementbyid ('img '). src = This. Value" />
< IMG ID = "IMG" >
</ Form >
</ Body >
</ Html >