file controls and image controls to implement a picture preview

Source: Internet
Author: User

Two ways: 1. Using JS to achieve
2. Add a statement directly to the control's event-handling function (equivalent to writing the function code of JS directly here, as in the comment premises)
Note: You can use the <input type= ' file ' > can also be implemented with <asp:FileUpload>, although the latter does not onchange events, but when forced to use, although prompted [Validation ( asp.net): attribute ' onchange ' is not a valid attribute of element ' FileUpload '], but the desired effect can be achieved.

 
 
  1. <body>
  2. <script type= "Text/javascript" >
  3. function Ch (val)
  4. {
  5. document.getElementById (' Image1 '). Src=val;
  6. }
  7. </script>
  8. <form id= "Form1" runat= "Server" >
  9. <div>
  10. <asp:image id= "Image1" runat= "Server" width= "135px"/>
  11. <%--<input id= "File1" type= "file" onchange= "document.getElementById (' Image1 '). Src=this.value"/>--%>
  12. <input id= "File1" type= "file" onchange= "ch (this.value);" />
  13. <asp:fileupload id= "FileUpload1" runat= "Server" onchange= "document.getElementById" (' Image1 '). Src=this.value "/ >
  14. </div>
  15. </form>
  16. </body>


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.