Ajax toolkit file upload is not called

ajax, ajaxcontroltoolkit, c#

Solution

We got the same problem yesterday and we found out that you cannot have more than one instance of AjaxFileUpload on the same page.

If you look at the source code, you'll see that this control use a constant GUID to identify its events. Since the GUID is a constant, all instances of AjaxFileUpload use the same GUID...

Result :

the first instance swallow all the events...

Here is the GUID in action :

private const string ContextKey = "{DA8BEDC8-B952-4d5d-8CC2-59FE922E2923}";

(...)

if (this.Page.Request.QueryString["contextkey"] == ContextKey && this.Page.Request.Files.Count > 0)

Problem

I have two ajaxtoolkit file ulopads on the same page like ``` <ajaxToolkit:AjaxFileUpload id="AjaxFileUpload1" AllowedFileTypes="jpg,jpeg,gif,png" OnUploadComplete="ajaxUpload2_OnUploadComplete" runat="server" /> <ajaxToolkit:AjaxFileUpload id="ajaxUpload1" AllowedFileTypes="jpg,jpeg,gif,png" OnUploadComplete="ajaxUpload1_OnUploadComplete" runat="server" /> ``` and code behind ``` protected void ajaxUpload2_OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { string filePath = "~/Images/" + e.FileName; filePath = filePath.Split('\\').Last(); Session["img2"] = filePath.ToString(); AjaxFileUpload1.SaveAs(MapPath(filePath)); } protected void ajaxUpload1_OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { string filePath = "~/Images/" + e.FileName; filePath = filePath.Split('\\').Last(); Session["img1"] = filePath.ToString(); ajaxUpload1.SaveAs(MapPath(filePath)); } ``` The question is whenever I use upload AjaxFileUpload1 it works on and calls void ajaxUpload2_OnUploadComplete method but if I use ajaxUpload1 the method ajaxUpload2_OnUploadComplete is called again but the method ajaxUpload1 is not called Why?? Thanks.

Original source