When I have multiples AjaxFileUpload controls on the same page, the event fired is always the same.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
onuploadcomplete="AjaxFileUpload1_UploadComplete" AllowedFileTypes=""
ContextKeys="1" MaximumNumberOfFiles="0" />
<asp:AjaxFileUpload ID="AjaxFileUpload2" runat="server"
MaximumNumberOfFiles="0" OnUploadComplete="AjaxFileUpload2_UploadComplete"
ContextKeys="2" />
<asp:AjaxFileUpload ID="AjaxFileUpload3" runat="server"
MaximumNumberOfFiles="0" OnUploadComplete="AjaxFileUpload3_UploadComplete"
ClientIDMode="AutoID" ContextKeys="3" />
</form>
</body>
</html>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//Only this event is fired, and allways with id=AjaxFileUpload1 and ContextKeys=1
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
AjaxFileUpload aj = sender as AjaxFileUpload;
string id = aj.ID;
string ContextKeys = aj.ContextKeys;
}
protected void AjaxFileUpload3_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
}
protected void AjaxFileUpload2_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
}
}
Comments: I think I've located the problem. It is in AjaxFileUpload.cs: ``` private void XhrComplete() { var filesInQueue = int.Parse(Page.Request.QueryString["queue"] ?? "0"); var filesUploaded = int.Parse(Page.Request.QueryString["uploaded"] ?? "0"); var reason = Page.Request.QueryString["reason"]; AjaxFileUploadCompleteAllReason completeReason; switch (reason) { case "done": completeReason= AjaxFileUploadCompleteAllReason.Success; break; case "cancel": completeReason= AjaxFileUploadCompleteAllReason.Canceled; break; default: completeReason = AjaxFileUploadCompleteAllReason.Unknown; break; } var args = new AjaxFileUploadCompleteAllEventArgs(filesInQueue, filesUploaded, completeReason); if (UploadCompleteAll != null) UploadCompleteAll(this,args); Page.Response.Write(new JavaScriptSerializer().Serialize(args)); } ``` It's the line at the end: ``` Page.Response.Write(new JavaScriptSerializer().Serialize(args)); ``` So, they all write back to the page.. then the first one gets picked up even if the control is inside an UpdatePanel. There could be similar issues with other events fired by the control. Could someone who is familiar with the code base please fix this? It is a fairly easy fix but probably a number of dependencies on that code above..
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
onuploadcomplete="AjaxFileUpload1_UploadComplete" AllowedFileTypes=""
ContextKeys="1" MaximumNumberOfFiles="0" />
<asp:AjaxFileUpload ID="AjaxFileUpload2" runat="server"
MaximumNumberOfFiles="0" OnUploadComplete="AjaxFileUpload2_UploadComplete"
ContextKeys="2" />
<asp:AjaxFileUpload ID="AjaxFileUpload3" runat="server"
MaximumNumberOfFiles="0" OnUploadComplete="AjaxFileUpload3_UploadComplete"
ClientIDMode="AutoID" ContextKeys="3" />
</form>
</body>
</html>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//Only this event is fired, and allways with id=AjaxFileUpload1 and ContextKeys=1
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
AjaxFileUpload aj = sender as AjaxFileUpload;
string id = aj.ID;
string ContextKeys = aj.ContextKeys;
}
protected void AjaxFileUpload3_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
}
protected void AjaxFileUpload2_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
}
}
Comments: I think I've located the problem. It is in AjaxFileUpload.cs: ``` private void XhrComplete() { var filesInQueue = int.Parse(Page.Request.QueryString["queue"] ?? "0"); var filesUploaded = int.Parse(Page.Request.QueryString["uploaded"] ?? "0"); var reason = Page.Request.QueryString["reason"]; AjaxFileUploadCompleteAllReason completeReason; switch (reason) { case "done": completeReason= AjaxFileUploadCompleteAllReason.Success; break; case "cancel": completeReason= AjaxFileUploadCompleteAllReason.Canceled; break; default: completeReason = AjaxFileUploadCompleteAllReason.Unknown; break; } var args = new AjaxFileUploadCompleteAllEventArgs(filesInQueue, filesUploaded, completeReason); if (UploadCompleteAll != null) UploadCompleteAll(this,args); Page.Response.Write(new JavaScriptSerializer().Serialize(args)); } ``` It's the line at the end: ``` Page.Response.Write(new JavaScriptSerializer().Serialize(args)); ``` So, they all write back to the page.. then the first one gets picked up even if the control is inside an UpdatePanel. There could be similar issues with other events fired by the control. Could someone who is familiar with the code base please fix this? It is a fairly easy fix but probably a number of dependencies on that code above..