Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
are it's possible which i'm trying ?




my jquery

XML
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js">
        function showimagepreview(input) {
            if (input.files && input.files[0]) {
                var filerdr = new FileReader();
                filerdr.onload = function (e) {
                    $('#Image1').attr('src', e.target.result);
                }
                filerdr.readAsDataURL(input.files[0]);
            }
        }
    </script>



fileupload1

VB
<asp:FileUpload ID="FileUpload1" runat="server"
           onchange="showimagepreview(this)"/>




i want preview at Image1

please help me to generate preview of upload image
Posted
Updated 22-Apr-14 20:44pm
v2
Comments
ravikhoda 23-Apr-14 1:51am    
as per my knowledge you can not directly view image which is not on your server(you can not access an image/file from the client machine directly). first you need to update the image on the server and than you can show the preview of that image.


may be upload the image to some temp directory

Problem


The problem is, Image1 Control is not declared on the Page.

Solution


Script


HTML
<script type="text/javascript">
    function showimagepreview(input) {
        if (input.files && input.files[0]) {
            var filerdr = new FileReader();
            filerdr.onload = function (e) {
                $('#<%= Image1.ClientID %>').attr('src', e.target.result);
            }

            filerdr.readAsDataURL(input.files[0]);
        }
    }
</script>

HTML


ASP.NET
<asp:FileUpload ID="FileUpload1" runat="server" onchange="showimagepreview(this)" />
<img id="Image1" alt="uploaded image preview" />
 
Share this answer
 
v2
Comments
neeraj_ 23-Apr-14 2:24am    
it's not working sir
It is perfectly working. Which browser you are testing in?
neeraj_ 23-Apr-14 2:26am    
what is the mean of
Image1 Control is not declared on the Page.
See the HTML I have posted... I have posted the Image1 control...
neeraj_ 23-Apr-14 2:41am    
i'm also using
<asp:Image ID="Image1" runat="server" Height="164px" Width="171px"
BackColor="Silver">
Hi Neeraj,

Try this.
XML
<div>
                <input type="file" name="filUpload" id="filUpload" onchange="showimagepreview(this)" />

<img id="imgprvw" alt="uploaded image preview"/>
            </div>



C#
function showimagepreview(input) {
            alert();
            if (input.files && input.files[0]) {
                var filerdr = new FileReader();
                filerdr.onload = function (e) {
                    $('#imgprvw').attr('src', e.target.result);
                }
                filerdr.readAsDataURL(input.files[0]);
            }
        }
 
Share this answer
 
v2
Comments
neeraj_ 23-Apr-14 2:38am    
not working sir
Ajith K Gatty 23-Apr-14 3:09am    
i tried it on FireFox. Working perfectly.
Where is it failing? Did you put an alert for input.files and input.files[0] to check the value? Instead try using input.value and check whether you are getting the file path.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900