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;
}
Re: image and fileupload control
Hello,
Do you get any client side JavaScript errors in FireFox? If so, what are they?
Gary
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.
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
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
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