2011-08-10 45 views
3

我有多個從C#後面的代碼創建的asyncfileupload控件,我無法弄清楚如何從我的代碼的UploadedComplete部分或任何實例中引用正確的控件實例。從後面的c#代碼創建多個AJAX asyncfileupload

我在一個頁面中使用了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"); 
} 

我怎樣才能像在我的上傳處理程序中出現的具體實例?

〜E

回答

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"); 
}