Reputation: 53
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
Upvotes: 3
Views: 2151
Reputation: 1907
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");
}
Upvotes: 1