简体   繁体   中英

Multiple AJAX asyncfileupload created from c# code behind

I have multiple asyncfileupload controls created from code behind C# and I can't figure out how to reference the right control instance from the UploadedComplete section of my code, or any instance for that matter.

I'm using 20 async file uploads in one page all in different modal popup controls so creating all my controls from code behind each fire when you click a button. So using only c# is absolutely necessary.

Each instance is created as follows:

AsyncFileUpload afuUploadEvents     = new AsyncFileUpload();
afuUploadEvents.ID                  = "AsyncFileUploadId";
afuUploadEvents.UploadedComplete   += new EventHandler<AsyncFileUploadEventArgs>this.afuUpload_UploadedComplete);
// other settings... blah blah blah... 

Here is the attempts to find the control:

protected void afuUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
    // get the file upload control - doesn't work
    AsyncFileUpload oFileUpload = (AsyncFileUpload)sender;
    // Try again - doesn't work
    ContainerElem.FindControl("AsyncFileUploadId");
}

How can I get the specific instance that is occurring in my upload handler?

~E

protected void AsyncFileUploadComplete(object oSender, AsyncFileUploadEventArgs e)
{
    try
    {   
        AsyncFileUpload oFileUploadControl = GetFileUploadInstance(ContainerId, (AsyncFileUpload)oSender);
    }
    catch (exception ex)
    {
    }
}

private AsyncFileUpload GetFileUploadInstance(Control oContainer, AsyncFileUpload oSender)
{

    // Place all of your popup controls in a global container, look for the sender as a child control
    foreach (Control oControl in oContainer.Controls)
        if (oControl.Controls.Count != 0 && oControl.FindControl("m_afuFileUpload") == oSender)
            return (AsyncFileUpload)oControl;

    return new AsyncFileUpload(); // || throw new Exception("Could not find ASyncFileUpload Instance");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM