Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asyncfileupload display image asp.net

Posted on 2012-04-06
3
Medium Priority
?
745 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:
Seven price earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

916 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