Search code examples
asp.netfile-uploadajaxcontroltoolkit

AjaxFileUpload doesn't fire OnUploadComplete Event


i am trying to get that AjaxFileUpload-Control(used in ContentPage) working. But it does not fire OnUploadComplete Event at server side

I am using version 4.1.60919.0 of the ControlToolkit. I have tried everything i found on the internet.

Here just a few steps:

  • Added enctype="multipart/form-data" method="post" to the form-element in my MasterPage
  • Nested the AjaxFileUpload into an UpdatePanel with UpdateMode=Always
  • Tried events UploadedComplete and OnUploadComplete, but stayed at the second one
  • Added a try-catch-block in the EventHandler to catch unknown exceptions and print the ExceptionMessage to a label on the site --> nothing happened
  • Tried it with(out) a ThrobberImage...
  • Many other tipps that did not work...

So, i hope we will find a solution together in this community. Heres my markup:

<%@ Page Title="New Download" Language="C#" MasterPageFile="~/MasterPage.master"     AutoEventWireup="true" CodeFile="NewDownload.aspx.cs" Inherits="Internals_NewDownload" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">

<ajax:ToolkitScriptManager ID="ToolkitscriptManager" runat="server">    </ajax:ToolkitScriptManager>
<h1>Create a new Download</h1>

        <ajax:AjaxFileUpload ID="FileUpload" runat="server" ThrobberID="ThrobberLabel" OnUploadComplete="FileUpload_UploadComplete" />
        <asp:Label ID="ThrobberLabel" runat="server" Style="display: none;"><img alt="UploadingPicture" title="Please wait while uploading..." src='<%= Constants.DomainString + "/Data/Images/loading-small.gif" %>' /></asp:Label>
        <asp:Label ID="DownloadLabel" runat="server"></asp:Label>

</asp:Content>

And this is my CodeBehind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Internals_NewDownload : System.Web.UI.Page
{
private string m_LanguageCode;

protected void Page_Load(object sender, EventArgs e)
{
    if (RouteData.Values.ContainsKey("LanguageCode"))
        m_LanguageCode = RouteData.Values["LanguageCode"].ToString();

    //if (IsPostBack)
    //    return;
    if (!User.IsInRole("Administrator") && !User.IsInRole("Kunde") && !User.IsInRole("Mitarbeiter"))
        Response.Redirect(Constants.DomainString + "/PermissionDenied.aspx");
    Session[Constants.NonGlobalizedString] = true;
    Session[Constants.MenuInfoSession] = new ClsMenuInfo("NewDownload");
}

protected void FileUpload_UploadComplete(object sender,     AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
    try
    {
        string filePath = "~/upload/" + e.FileName;
        DownloadLabel.Text = filePath;
    }
    catch (Exception ex)
    {
        DownloadLabel.Text = ex.Message;
    }
}
}

Please, if you have ANY idea, do not hesitate to let me know it. I am very confused as i think that i just did in that howtos i found on the internet...

Thanks in advance!


Solution

  • Take into account that AjaxFileUpload control use contextkey QueryString parameter to detect own postback. I believe the reason of you issue is that this parameter lost in result of rewriting url. I'm not expert in applying routing but in my opinion you need to register contextkey parameter in routing tables and tweak AjaxControlToolkit sources to use RouteData instead of Request.QueryString for retrieving it value. Check this link for more info: AjaxControlToolkit Source Code