Solved

asyncfileupload display image asp.net

Posted on 2012-04-06
3
720 Views
Last Modified: 2012-06-04
Using AsyncFileUpload how do you display the image when uploadcompleted fires. Have seen refererence to using Javascript but this doesn't work.
0
Comment
Question by:cehrnow
3 Comments
 
LVL 9

Accepted Solution

by:
sevensnake77 earned 500 total points
ID: 37816005
To display the image after the UploadedComplete event is fired, we need to register a script which is used to set the image’s src property.
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>


    <script runat="server">
        protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)

        {


            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'Uploaded size: " + AsyncFileUpload1.FileBytes.Length.ToString() + "';", true);



            string savePath = MapPath("~/Uploads/" + System.IO.Path.GetFileName(e.filename));

            AsyncFileUpload1.SaveAs(savePath);


            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "image", "top.$get(\"" + Image1.ClientID + "\").src = 'Uploads/" + System.IO.Path.GetFileName(e.filename) + "';", true);



        }
    </script>


</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                Please upload a image:<br />
                <cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />

                <br />
                <br />
                Here is your image:<br />
                <asp:Label runat="server" Text=" " ID="uploadResult" /><br />
                <asp:Image ID="Image1" runat="server" /></ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 38043700
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question