views:

70

answers:

1

I have to implement an image upload functionality in asp.net. The method I have followed works like this :-

Submit a form containing an <input type='file'> element and set the target of the form to a named iframe[to give the impression of a Ajax request/response ]. The aspx file which this form is posted to, writes the image into the response as Reponse.Write("<img src='location'/>"); The image displayed is due for cropping (where i plan to use JCrop).

What I would like to know is : Is there another way to display the image in a <div> may be, rather than in an iframe which I think is far better than this approach.

+1  A: 

If you have or can get access to the 'location' value you certainly have everything you need to be able to add a div element to your response:

Response.Write("<div><img src='location'/></div>");

Or possibly use something like jQuery to simply set the content of an existing div:

$("#uploadedImage").html("<img src='location' />");

In your HTML document:

<div id="uploadedImage"></div>
JonathanK
where will the response be written in this case? in the target of the form being submitted rite.. what will be the target then????
Ajay
The target would still be a form, i.e., upload.aspx or possibly even the current page being viewed. To avoid the appearance of a postback you will need to leverage an actual Ajax call.
JonathanK
is an ajax call possible to upload a file?
Ajay