file controls and image controls to implement a picture preview

Source: Internet
Author: User
Tags implement

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>


Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.