Results 1 to 6 of 6

Thread: image and fileupload control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    image and fileupload control

    hi guys, i have a combined control to display image using fileupload and image controls. the code below works perfectly for IE browser but for some reason it wont give me the desired result using firefox and chrome. would you suggest other work around?

    cheers.


    html
    Code:
    <asp:FileUpload ID="FileUpload1" runat="server" />
    vb
    Code:
    FileUpload1.Attributes.Add("onchange", "javascript:LoadImage();")
    javascript
    Code:
    function LoadImage(){
    document.getElementById('imgImage').src=document.getElementById('FileUpload1').value;      
    }
    Learn something new every .001 second.

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: image and fileupload control

    Hello,

    Do you get any client side JavaScript errors in FireFox? If so, what are they?

    Gary

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: image and fileupload control

    Hey,

    Strange but I'm not getting javascript error from firefox. But it replace the default image by blank canvas after file selection.
    Last edited by jlbantang; Mar 27th, 2011 at 08:38 AM.
    Learn something new every .001 second.

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: image and fileupload control

    Hello,

    Ok to be clear, have you opened the JavaScript error console in FireFox? It doesn't show by default.

    What is the value of

    Code:
    document.getElementById('FileUpload1').value;
    When the LoadImage function is called?

    Gary

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: image and fileupload control

    Hi Gary,

    I just rewrite the javascript function and add document.write() to get a print of selected path.

    While IE gives a full qualified path after selecting the image what happen in Firefox is different as it return only File Name itself.

    IE
    D:\images\thumbnail\myimage.jpeg

    FireFox
    myimage.jpeg
    Learn something new every .001 second.

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: image and fileupload control

    Hello,

    This is a known difference in the way browsers handle the FileUpload control. The FileUpload control is very browser specific, and each browser renders and handles the control in a different way. You will need to guard against this in your JavaScript code, or perhaps using jQuery, to make sure you know which way you want to handle it.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width