ajaxfileupload 页面上的多个输入 [英] ajaxfileupload multiple inputs on page

查看:35
本文介绍了ajaxfileupload 页面上的多个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ajaxFileUpload,如下所述:http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx

I'm using ajaxFileUpload as described here: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx

它工作正常,除非我在同一页面上有多个文件上传控件.具体来说,我正在尝试为不同的问题上传不同的文件.当我上传页面上的第一个时,它工作正常,但页面下方的那个只会将其文件上传到第一个问题的答案中.

It is working fine except when I have multiple file upload controls on the same page. Specifically, I am trying to upload different files for different questions. When I upload the first on the page, it works fine, but the one lower down on the page will only upload it's file into the answer for the first question.

我不确定这是否有意义...所以它可以帮助您了解我的页面使用 ascx 文件动态填充了问题.文档 ascx 文件如下所示:

I'm not sure that makes sense... so it may help you to know that my page is populated with questions dynamically using ascx files. The document ascx file looks like this:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Document.ascx.cs" Inherits="ScholarshipApplication.controls.questions.Document" %>


<ajaxToolkit:AjaxFileUpload OnUploadComplete="UploadComplete"  ID="FileUploadControl" MaximumNumberOfFiles="1" runat="server" AllowedFileTypes="png,jpg,jpeg,pdf,tiff,tif,gif" />
<asp:LinkButton ID="downloadButton" runat="server" CausesValidation="false" OnClick="downloadButton_Click" />

以及背后的代码:

public void UploadComplete(object sender, AjaxFileUploadEventArgs e)
        {
            entry.data = e.FileName;
            entry.setDocumentData(e.GetContents());

            this.downloadButton.Text = e.FileName;
        }

我最初的想法是,我需要以某种方式帮助控件生成的 javascript 知道它应该在何时触发哪个问题.

My initial thoughts are that somehow I need to help the control's generated javascript to know which question it should be triggering when.

推荐答案

我相信这是控制中的错误,或者这是由一些不明显的原因实现的.实际上,此控件不支持页面上的多个实例.考虑使用 AsyncFileUpload 控件 代替或自定义AjaxFileUpload 控件.如果您更喜欢第二个选项,那么您需要从这里下载源:http://ajaxcontroltoolkit.codeplex.com/SourceControl/BrowseLatest 并更改 AjaxFileUpload.cs 文件(这里是一个路径:/Server/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs).您需要做的是将 ContextKey 常量更改为属性,以便将上下文键 guid 与控件的唯一 id 结合起来:

I believe this is a bug in control or this was implemented by some non-obvious reason. Actually, this control doesn't support multiple instances on a page. Consider to use AsyncFileUpload control instead or customize a bit sources of the AjaxFileUpload control. If you prefer second option then you need to download sources from here: http://ajaxcontroltoolkit.codeplex.com/SourceControl/BrowseLatest and change AjaxFileUpload.cs file (here is a path: /Server/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs). What you need to do is to change ContextKey constant to property for combining context key guid with unique id of control:

public class AjaxFileUpload : ScriptControlBase
{
    private const string ContextKeySuffix = "{DA8BEDC8-B952-4d5d-8CC2-59FE922E2923}";

    private string ContextKey
    {
        get { return this.UniqueID + "_" + ContextKeySuffix; }
    }

实际上,如果您查看 AjaxFileUpload 类的 PreRender 方法,您将很容易意识到该控件的这种行为(第一个控件句柄从所有页面上的同级控件).

Actually, if you'll look on PreRender method of AjaxFileUpload class you'll easy realize reson for such behavior of this control (the first control handle uploads from all sibling controls on a page).

这篇关于ajaxfileupload 页面上的多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆