[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Updating an updatepanel after fileupload

Asked by Pichto in Programming for ASP.NET, C# Programming Language, Microsoft Visual C#.Net

Tags: ajax, .net, c#

Hi all,

I have a question :

On a web page (that i would like to have ajaxed) i put an AJAX upload component which works great.

Now what i want to do is to have on that same page an updatepanel that will display the content of the upload target folder (only images in my case).

Once i load the page, everything works fine : i can see my files and i can upload new files. The problem is that when upload is done, the updatepanel doesn't refresh to reflect changes on the server. How could i make that work ?

Below is my code (ASPX and below, c#)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="FUA" Namespace="Subgurim.Controles" 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>Mon test à moi!!</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"
         EnablePartialRendering="true">
    </asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Block" >
        </asp:UpdatePanel> 
        <cc1:FileUploaderAJAX ID="FileUploaderAJAX1" runat="server" 
                    text_Add="Ajouter" 
                    text_Delete="Effacer" 
                    text_Uploading="Chargement en cours" />
    </div>
    </form>
</body>
</html>
 
C#  :
 
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Subgurim.Controles;
using System.IO;
 
public partial class _Default : System.Web.UI.Page 
{
    private String ImageFolder = "~/temp";
    private Int32 ImgPerRow = 8;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager1.RegisterAsyncPostBackControl(FileUploaderAJAX1);
 
        if (FileUploaderAJAX1.IsPosting)
            this.managePost();
 
        if (!Page.IsPostBack)
        {
            GenerateImagesTable();
        }
    }
 
    private void managePost()
    {
        //Response.Write("test");
 
        HttpPostedFileAJAX pf = FileUploaderAJAX1.PostedFile;
 
        if ((pf.ContentType.Equals("image/gif") || pf.ContentType.Equals("image/jpeg") || pf.ContentType.Equals("image/pjpeg")) && pf.ContentLength <= 100 * 1024)
            FileUploaderAJAX1.SaveAs("~/temp", pf.FileName);
 
        
        GenerateImagesTable();
 
        UpdatePanel1.Update();
    }
 
    private void GenerateImagesTable()
    {
        DirectoryInfo dir = new DirectoryInfo(MapPath(ImageFolder));
        FileInfo[] files = dir.GetFiles();
 
        //UpdatePanel1.Controls.Clear();
 
        UpdatePanel1.ContentTemplateContainer.Controls.Clear();
        //PlaceHolder1.Controls.Clear();
 
        if (files.Length == 0)
        {
            UpdatePanel1.ContentTemplateContainer.Controls.Add(new LiteralControl("Pas de fichiers présents dans ce dossier"));
 
            return;
        }
 
        Table ImgTable = new Table();
        TableRow ImgTableRow = new TableRow();
        TableCell ImgTableCell = new TableCell();
 
        UpdatePanel1.ContentTemplateContainer.Controls.Add(ImgTable);
 
        ImgTable.Rows.Add(ImgTableRow);
 
        ImgTable.Width = Unit.Percentage(100);
 
        Int32 i = 0;
        foreach (FileInfo file in files)
        {
            String FileName = file.Name;
            if (i++ == ImgPerRow)
            {
                ImgTableRow = new TableRow();
                ImgTable.Rows.Add(ImgTableRow);
 
                i = 1;
            }
 
            ImgTableCell = new TableCell();
            ImgTableRow.Cells.Add(ImgTableCell);
 
            ImgTableCell.HorizontalAlign = HorizontalAlign.Center;
            ImgTableCell.Width = Unit.Percentage(12.5);
 
            Image myImage = new Image();
            myImage.ImageUrl = ImageFolder + "/" + FileName;
            myImage.Width = Unit.Pixel(50);
            myImage.Height = Unit.Pixel(50);
 
            ImgTableCell.Controls.Add(myImage);
        }
    }
}
[+][-]01/02/08 03:25 AM, ID: 20563654Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/02/08 03:45 AM, ID: 20563702Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/02/08 09:21 AM, ID: 20565908Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming for ASP.NET, C# Programming Language, Microsoft Visual C#.Net
Tags: ajax, .net, c#
Sign Up Now!
Solution Provided By: noulouk
Participating Experts: 1
Solution Grade: A
 
[+][-]01/03/08 04:55 AM, ID: 20572351Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_EXPERT_20070906