文件上传字段获取空值

本文关键字:获取 空值 字段 文件 | 更新日期: 2023-09-27 18:33:18

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

如下所示
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);

文件上传字段获取空值

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

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