多视图中的文件上传总是显示 fileuplode.HasFiles False

File Upload Inside Multi-view always shows fileuplode.HasFiles False

我在多视图中有 3 个视图,在第二个视图中我有 FileUpload Control。 我在 button_click 上提交了第三个视图的所有值。 问题是当我点击提交按钮时 fileuplode.HasFiles 总是显示错误, 我知道它显示错误,因为文件上传控件在网页上不可见。但是有什么方法可以从视图 2 上的 Fileupload 控件获取发布的文件详细信息并在视图 3 上提交该值..

这是View2的代码

 <div class="form-group">
        <label for="InputMessage">Written Note From Doctor (Approval Note)</label>
        <div class="input-group">
        <asp:FileUpload runat="server" ID="drFileUpload" placeholder="Doctor Note" class="fileupload" />
           </div>
         </div>
      <asp:Button runat="server" CssClass="btn btn-success" Text="Previous" ID="Button1" OnClick="activeView0" />
  <asp:Button runat="server" CssClass="btn btn-success" ID="txtnext2" Text="Next" OnClick="activeView2" ValidationGroup="view2" TabIndex="1" />

在视图 3 上,我提交了所有值

这是视图 3

上 Button_click 的代码

`

if (drFileUpload.HasFiles)
   {
   string filename = drFileUpload.PostedFile.FileName;
   string extention = Path.GetExtension(filename);
  if (extention.ToLower() == ".jpg" | extention.ToLower().ToLower() == ".png" | extention.ToLower().ToLower() == ".jpeg")
       {
       filename = txtMobile.Text;
       int width=Convert.ToInt32(ConfigurationManager.AppSettings["ProfilePicWidth"]);
       string Destination = Convert.ToString(Server.MapPath("../Images/Members/" + filename + extention));
       CommanFunctions.ResizeImage(width, drFileUpload.PostedFile.InputStream, Destination);
      regi.ProfilePic = Destination;
       }
 else
      {
      lblError.Text = "Please Upload a valid Image";
      multiview.ActiveViewIndex = 1;
      }
   }
else
 {
   regi.ProfilePic = null;
 }

我尝试在更新面板中结束代码,但它不起作用。

我自己找到了解决方案,因为我在更改视图时将文件存储为 HttpPostedFile 在会话中

   protected void activeView2(object sender, EventArgs e)
    {
        multiview.ActiveViewIndex = 2;
       // storing uploaded file into sessin view HttpPostedFile
        HttpPostedFile file = drFileUpload.PostedFile;
        Session["f1"] = file;

    }

并且在提交时我正在检索 HttpPostedFile

  // getting the image file from the stream and saving to server
                HttpPostedFile f1 = (HttpPostedFile)Session["f1"];
                int nFileLen = f1.ContentLength;
                byte[] myData = new byte[nFileLen];
                f1.InputStream.Read(myData, 0, nFileLen);

                if (f1.ContentLength != 0)
                {
                    string filename = f1.FileName;
                    string extention = Path.GetExtension(filename);
                    if (extention.ToLower() == ".jpg" | extention.ToLower().ToLower() == ".png" | extention.ToLower().ToLower() == ".jpeg")
                    {
                        filename = txtMobile.Text;
                        int width = Convert.ToInt32(ConfigurationManager.AppSettings["ProfilePicWidth"]);
                        string Destination = Convert.ToString(Server.MapPath("../Images/Members/" + filename + extention));
                        CommanFunctions.ResizeImage(width, f1.InputStream, Destination);
                        regi.ProfilePic = Destination;
                    }
                    else
                    {
                        lblError.Text = "Please Upload a valid Image";
                        multiview.ActiveViewIndex = 1;
                    }
                }

希望这对以后的人有帮助