gpt4 book ai didi

c# - 从后面的 c# 代码创建的多个 AJAX asyncfileupload

转载 作者:行者123 更新时间:2023-11-30 18:41:16 26 4
gpt4 key购买 nike

我有多个从 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");
}

如何获取上传处理程序中发生的特定实例?

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

关于c# - 从后面的 c# 代码创建的多个 AJAX asyncfileupload,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7009072/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com