我有多个从C#后面的代码创建的asyncfileupload控件,我无法弄清楚如何从我的代码的UploadedComplete部分或任何实例中引用正确的控件实例。
我在一个页面中使用20个异步文件上传,所有这些都在不同的模态弹出控件中,因此当您单击按钮时,从每个火灾后面的代码创建我的所有控件。因此,仅使用c#是绝对必要的。
每个实例创建如下:
AsyncFileUpload afuUploadEvents = new AsyncFileUpload();
afuUploadEvents.ID = "AsyncFileUploadId";
afuUploadEvents.UploadedComplete += new EventHandler<AsyncFileUploadEventArgs>this.afuUpload_UploadedComplete);
// other settings... blah blah blah...
以下是尝试找到控件:
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");
}
如何获取上传处理程序中发生的特定实例?
〜戊
答案 0 :(得分:0)
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");
}