Solved

asyncfileupload display image asp.net

Posted on 2012-04-06
3
714 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now