1

这是我的问题。我正在动态添加文件上传字段并将每个文件上传字段添加到集合中,如下所示

static List<FileUploadField> fuploadcollection = new List<FileUploadField>();

,到目前为止一切顺利。但是当我尝试在文件上传字段中上传图像时,我得到了空的文件上传字段。但是当我通过断点观看它时,它似乎填充了“fuploadcollection”集合。

这是我的代码;

添加文件上传功能;

    public partial class UserControl1 : System.Web.UI.UserControl
    {
        static int? _currentflag = 0;

        static List<FileUploadField> fuploadcollection = new List<FileUploadField>();

........
........
.........
       protected void addImages_Click(object sender, DirectEventArgs e)
            {
                int? nn = null;

                X.Msg.Alert("hello", "hello").Show();
                _currentflag = (!string.IsNullOrEmpty(txtcurrentflag.Text)) ? Convert.ToInt32(txtcurrentflag.Text) : nn;
                FileUploadField fileUploadField = new FileUploadField()

                {
                    ID = "FileUploadField" + _currentflag,
                    Width = 280,
                    Icon = Icon.Add,
                    ClientIDMode = ClientIDMode.Static,
                    Text = "Göz at",
                    FieldLabel = "Resim-" + _currentflag,
                    Flex = 1,
                    ButtonText="resim seç"

                };

                fileUploadField.AddTo(this.pnlResim, true);
                if (string.IsNullOrEmpty(txtcurrentflag.Text) || txtcurrentflag.Text == "0")
                {
                    fuploadcollection.Clear();
                }
                fuploadcollection.Add(fileUploadField);

                _currentflag++;
                txtcurrentflag.Text = _currentflag.ToString();


            }

这是给出错误的这部分(无法输入 if 语句)*,但似乎 fuploadcollection 已填充(例如,它的计数显示多于 1)

            foreach (var item in fuploadcollection)
                {
                    if (item.HasFile)
                    {
                        string resimadi = UploadImage.UploadImages(item);
4

1 回答 1

2

如果您创建动态控件,您应该在每个请求期间重新创建它们。有一些链接,可能会有所帮助:

http://forums.ext.net/showthread.php?19315

http://forums.ext.net/showthread.php?19079

http://forums.ext.net/showthread.php?9224

http://forums.ext.net/showthread.php?16119

http://forums.ext.net/showthread.php?23402

于 2013-10-01T00:43:42.823 回答