Hi Everyone,
I'm trying to have a user upload a picture (using AjaxFileUpload), and once uploaded, display that image in an Image Control.
The problem is that even though I can upload and save the selected image to the server without problem, when I set the Image Control's ImageURL tag, nothing happens. i.e. the uploaded image is not displayed.
Here is my code:
<asp:UpdatePanel ID="upTop" runat="server" UpdateMode="Conditional"><ContentTemplate><asp:Panel ID="Panel1" CssClass="panelbox" runat="server"><table><tr><td><asp:Image ID="imgClient" runat="server" /></td><td><ajaxToolkit:AjaxFileUpload ID="ajaxUpload1" ThrobberID="MyThrobber" runat="server" MaximumNumberOfFiles="1" OnUploadComplete="ajaxUpload1_UploadComplete"AllowedFileTypes="jpg,jpeg" /><asp:Image ID="MyThrobber" ImageUrl="~/Images/pleasewait.gif" Style="display: None" runat="server" /></td></tr></table></asp:Panel></ContentTemplate></asp:UpdatePanel>
And Code-Behind:
Sub ajaxUpload1_UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs)
Dim Filepath As String Dim NewFileName As String Filepath = "/ClientPhotos" NewFileName = MapPath(Filepath) & "\NewImage.jpg" Try ajaxUpload1.SaveAs(NewFileName) Catch ex As Exception ShowError("Error uploading photo: " & ex.Message) Exit Sub End Try Me.imgClient.ImageUrl = "~/ClientPhotos/NewImage.jpg" Me.imgClient.Width = 500 Me.imgClient.Height = 500 End Sub
As mentioned above, the file uploads ok and is saved with the correct filename as expected. During debuging, I can confirm that the code-behind supplied above is definitely triggering, including the setting of the ImageUrl. The path for the imageUrl is correct.
Can someone please explain why the image control is not updating? Even better, can someone please help with a way to achieve what I'm trying to do?
Thanks in advance for any assistance you can offer.
Mary.