locked
Dynamically displaying a bunch images using Ajax RRS feed

  • Question

  • User-1561933206 posted

    Hi,

    I have a bunch of images stored in a List<string> storing the paths of the images which I have obtained using AjaxFileUpload.

    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager>
    <asp:ajaxfileupload ID="Ajaxfileupload1" runat="server" OnUploadComplete="FileUploadComplete" OnUploadCompleteAll="FileUploadCompleteAll" EnableViewState="true" >
    </asp:ajaxfileupload>
    
    <asp:UpdatePanel ID="_updatePanel" runat="server">
                
      <ContentTemplate>
                    
         <asp:PlaceHolder ID="_ph" runat="server">
                        
         </asp:PlaceHolder>
      </ContentTemplate>
    </asp:UpdatePanel>

    In codebehind, I have

    protected void FileUploadCompleteAll(object sender, System.EventArgs e)
    {
      for (int i = 0; i < fN.Count; i++)
      {
         System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
         img.ImageUrl = fN[i];
         _ph.Controls.Add(img);
    
      }        
    }

    fN is a List<string> and has all the image paths.

    Please let me know what wrong I am doing here and a possible fix.

    Thank you

    Friday, April 18, 2014 8:10 PM

Answers

All replies

  • User1208776063 posted

    img.ImageUrl = fN[i];

    You need to make sure that images are downloaded to some temporary location on the server. Then, you can use Server.MapPath("~/tempImages/"+Path.GetFileName(fn[i])); Otherwise, uploaded file path will the path of the file on client's machine such as C://myfile.jpg.  Debug and see what's being saved in the list fn.

    Friday, April 18, 2014 8:33 PM
  • User-1561933206 posted

    Hi dotnetzoom,

    fN[i] does have the complete path of the images. Could the problem be related to the PlaceHolder I am using?

    I tried using Panel instead of PlaceHolder but even that didn't work. Am I suppose to use some kind of RenderControl to display the images?

    When I try to debug, images get added to the PlaceHolder but nothing happens at the end of FileUploadAll method.

    Saturday, April 19, 2014 12:30 AM
  • User-933407369 posted

    i would suggest you try the code or place the Ajaxfileupload into the UpdatePanel :

       _updatePanel.FindControl("_ph").Controls.Add(img);

    please refer to the link for details:

    Understanding ASP.NET AJAX UpdatePanel Triggers

    http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 21, 2014 2:51 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 22, 2014 12:25 AM