Dibyajyoti Palata

Dibyajyoti Palata

  • 1.5k
  • 275
  • 14.3k

OnUploadedComplete not firing

Apr 27 2020 7:54 AM
  1. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxToolkit" %> 
  2. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>  
  3. <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">  
  4. <script type="text/javascript">  
  5. function AjaxFileUpload1_ClientUploadComplete(sender, e) {  
  6. if (sender._filesInQueue[sender._filesInQueue.length - 1]._isUploaded)  
  7. __doPostBack("<%= btnViewGallery.UniqueID %>""");  
  8. // Needed to do a postback to refresh gridview only after all files have been uploaded  
  9. }  
  10. </script>  
  11. </asp:Content>  
  12. <asp:Content ID="Content2" ContentPlaceHolderID="CommonHeaderContentPlaceHolder" Runat="Server">  
  13. <asp:ScriptManager ID="ScriptManager1" runat="server">  
  14. </asp:ScriptManager>  
  15. <asp:UpdatePanel id="UpdatePanel1" runat="server">  
  16. <ContentTemplate>  
  17. <asp:HiddenField ID="hdnId" runat="server" />  
  18. <asp:HiddenField ID="hdnType" runat="server" />  
  19. <div style="width:100%;">  
  20. <div class="lblPageHeader">  
  21. Gallery Image Upload  
  22. </div>  
  23. <div style="width:100%;padding:5px;">  
  24. <span class="lblClass" >Gallay Category :</span>  
  25. <asp:DropDownList ID="ddlGallaryCategory" runat="server" Width="220px" class="ddlClass" AutoPostBack="true" OnSelectedIndexChanged="fn_loadGallery" ViewStateMode="Enabled">  
  26. </asp:DropDownList>  
  27. </div>  
  28. <div style="width:100%;">  
  29. <AjaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" IsInFileUploadPostBack="true" mode  
  30. OnClientUploadComplete="AjaxFileUpload1_ClientUploadComplete"  
  31. OnUploadedComplete ="AjaxFileUpload1_UploadComplete"/>  
  32. </div>  
  33. <div style="width:100%;">  
  34. <asp:DataList ID="dlImages" runat="server" RepeatColumns="0" RepeatDirection="Horizontal" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3">  
  35. <AlternatingItemStyle BackColor="#DCDCDC" />  
  36. <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />  
  37. <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />  
  38. <ItemStyle BackColor="#EEEEEE" ForeColor="Black" />  
  39. <ItemTemplate>  
  40. <table border="0" style="width:100%;border-bottom-color:#60BAEA;border-top-color:#60BAEA;border-left-color:#60BAEA;border-left-color:#60BAEA;" cellspacing="5">  
  41. <tr>  
  42. <td align="center" style="padding:5px;width:100%;">  
  43. <asp:Image ID="img" runat="server" align="center" BorderStyle="Solid" BorderColor="#e0ddd7" BorderWidth="1" Height="50" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "IMAGE_PATH") %>' />  
  44. <br />  
  45. <asp:LinkButton ID="RemoveLinkBtn" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "IMAGE_ID") %>' OnCommand="RemoveLinkBtn_Command" >Remove</asp:LinkButton>  
  46. </td>  
  47. </tr>  
  48. </table>  
  49. </ItemTemplate>  
  50. <SelectedItemStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />  
  51. </asp:DataList>  
  52. </div>  
  53. </div>  
  54. <center><asp:Button ID="btnViewGallery" runat="server" Text="View Gallery" OnClick="btnViewGallery_Click" /> </center>  
  55. </ContentTemplate>  
  56. </asp:UpdatePanel>  
  57. </asp:Content>  
Code :
  1. #region Ajax Upload File  
  2. protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)  
  3. {  
  4. string filePath = string.Empty;  
  5. try  
  6. {  
  7. string strID = Session["selectedid"].ToString();  
  8. int compid = Convert.ToInt32(Session["COMPID"]);  
  9. filePath = (Server.MapPath("~/fileupload/gallery/") + Guid.NewGuid() + System.IO.Path.GetFileName(e.FileName));  
  10. AjaxFileUpload1.SaveAs(filePath);  
  11. string strFile = filePath.Substring(filePath.LastIndexOf("\\"));  
  12. string strFileName = strFile.Remove(0, 1);  
  13. string strFilePath = "~/fileupload/gallery/" + strFileName;  
  14. string input = Server.MapPath("fileupload/gallery/") + strFileName;  
  15. string thumb = Server.MapPath("fileupload/gallery/thumb/") + strFileName;  
  16. string output = Server.MapPath("fileupload/gallery/display/") + strFileName;  
  17. // Load image.  
  18. System.Drawing.Image image = System.Drawing.Image.FromFile(input);  
  19. Size thumbnailSize = GetImageSize(image, 110);  
  20. System.Drawing.Image thumbnail = resizeImage(image, thumbnailSize);  
  21. thumbnail.Save(thumb);  
  22. Size displaySize = GetImageSize(image, 640);  
  23. System.Drawing.Image display = resizeImage(image, displaySize);  
  24. display.Save(output);  
  25. // Compute thumbnail size, Get thumbnail & Save thumbnail.  
  26. /*  
  27. Size thumbnailSize = GetImageSize(image,110);  
  28. System.Drawing.Image thumbnail = image.GetThumbnailImage(thumbnailSize.Width,  
  29. thumbnailSize.Height, null, IntPtr.Zero);  
  30. thumbnail.Save(thumb);  
  31. }  
  32. catch (Exception ex)  
  33. {  
  34. Response.Write(ex.Message.ToString());  
  35. }  
  36. }  
  37. #endregion  

Answers (1)