Uploading image with AsynFileUpload(ACT Control) and changing Image Url of an Image Control??

Posted by mahdiahmadirad on Stack Overflow See other posts from Stack Overflow or by mahdiahmadirad
Published on 2010-06-06T16:53:24Z Indexed on 2010/06/06 17:02 UTC
Read the original article Hit count: 613

Hi!
I Used AsyncFileUpload(one of Ajac Control Toolkit Controls) to Uploading User's Image. this works well. But i want to change the image url of an image contorl to uploaded image url. how can i perform that? I put Image control in a Update Panel:

<asp:UpdatePanel ID="UpdatePanelNew" runat="server">
    <ContentTemplate>
        <asp:Image ID="Image1" ImageUrl="~/Images/Categories/NoCategory.png" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>
<asp:AsyncFileUpload OnClientUploadError="uploadError" OnClientUploadComplete="uploadComplete"
    runat="server" ID="AsyncFileUpload1" UploadingBackColor="#CCFFFF" ThrobberID="myThrobber" />
&nbsp;
<asp:Label ID="myThrobber" runat="server" Style="display: none;">
<img align="middle" alt="Working..." src="../../Images/App/uploading.gif" />
</asp:Label>

in C# code I wrote these:

protected void Page_Init()
{
    AsyncFileUpload1.UploadedComplete += new EventHandler<AsyncFileUploadEventArgs>(AsyncFileUpload1_UploadedComplete);
}

void AsyncFileUpload1_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "size", "top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'Uploaded size: " + AsyncFileUpload1.FileBytes.Length.ToString() + "';", true);

    string savePath = MapPath("~/Images/Categories/" + Path.GetFileName(e.filename));

    ImageOperations.ResizeFromStream(savePath, 128, AsyncFileUpload1.FileContent);

    Image1.ImageUrl = "~/Images/Categories/" + AsyncFileUpload1.FileName;

    //AsyncFileUpload1.SaveAs(savePath);
}

But it does not work. can you help me?
Note that ImageOperations.ResizeFromStream() method resizes and saves the image to a specefic folder.
actually I should trigger a Postback to Update the Update Panel but How to do that. I used UpdatePanelNew.Update(); but it does not work!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-ajax