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

发布于 2024-11-29 08:31:19 字数 880 浏览 1 评论 0原文

我有多个从 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强者自强 2024-12-06 08:31:19
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");
}
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");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文