[Original] image preview image Preview

Source: Internet
Author: User

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 >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.