2015-12-09 91 views
0

我有3視圖內多視圖和第二個視圖我有FileUpload控制。 我在button_click的第三個視圖上提交所有值。 問題是當我點擊提交按鈕fileuplode.HasFiles總是顯示錯誤, 我知道它顯示錯誤,因爲文件上載控件在網頁上不可見。但是,有沒有什麼辦法讓從FileUpload控件這是對圖2和提交有關視圖3該值發佈文件的詳細信息..文件上傳多視圖總是顯示fileuplode.HasFiles假

這裏是視圖2

的代碼
<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我我提交的所有值

這裏是Button_click對VIEW3

`

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; 
} 
代碼

我試圖在更新面板中包裝代碼,但它不起作用。

回答

0

我已經找到解決辦法我自己,因爲我在會議上存儲文件爲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; 
        } 
       } 

希望這將有助於有人在將來