AjaxFileUpload doesn't fire OnUploadComplete Event
Asked Answered
T

1

6

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!

Tricot answered 24/1, 2013 at 11:47 Comment(0)
A
0

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

Admetus answered 24/1, 2013 at 13:33 Comment(8)
Hi, thanks for this suggestion. I just tried the following. I removed the first two lines which are reading the LanguageCode from the RouteData-Collection. Hereafter i opened the page by the native path (/Internals/NewDownload.aspx instead of /Internals/de/NewDownload.aspx), but the problem still exists. The event does not get fired... :-( Just BTW: It is meant to post an answer at this website as a comment or as a new post to my question?Tricot
@Tricot that's ok to post a comment to answers. Also, why think that UploadComplete event doesn't fired? Did you tried to set breakpoint at FileUpload_UploadComplete method begin? Be warned, that DownloadLabel text will not be updated on UploadComplete event handler even if event firedAdmetus
I did only test it by having a look at DownloadLabel... Why should it NOT be updated?Tricot
Oh my god... You are RIGHT. The Breakpoint get hit, but my Label does NOT get updated with the new Text... Why does this happen?! EDIT: Nested the AjaxFileUpload and DownloadLabel into an UpdatePanel with UpdateMode="Always", but the Label still gets not updated...Tricot
cause uploading processed in separate frame from javascript. follow this link: #12097545Admetus
Your link seems to be not working for me. I tried it with and without an UpdatePanel... Following Code in the Eventhandler: string feedbackString = "~/upload/" + e.FileName; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "feedbackScript", "top.$get(\"" + DownloadLabel.ClientID + "\").value = '" + feedbackString + "';", true);Tricot
Even just a simple ScriptManager.RegisterStartupScript(this, this.GetType(), "test2", "javascript:alert('hi')", true); does not work... why?Tricot
let us continue this discussion in chatAdmetus

© 2022 - 2024 — McMap. All rights reserved.