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.
- <body>
- <script type= "Text/javascript" >
- function Ch (val)
- {
- document.getElementById (' Image1 '). Src=val;
- }
- </script>
- <form id= "Form1" runat= "Server" >
- <div>
- <asp:image id= "Image1" runat= "Server" width= "135px"/>
- <%--<input id= "File1" type= "file" onchange= "document.getElementById (' Image1 '). Src=this.value"/>--%>
- <input id= "File1" type= "file" onchange= "ch (this.value);" />
- <asp:fileupload id= "FileUpload1" runat= "Server" onchange= "document.getElementById" (' Image1 '). Src=this.value "/ >
- </div>
- </form>
- </body>