问题
I have 3 Views inside Multi-view and on second view I have FileUpload Control . I am submitting all values on third view on button_click. the problem is when i click the submit button fileuplode.HasFiles is always showing false, I know its showing false because File Upload control is not visible on Webpage. But is there any way to get the posted file details from Fileupload control which is on view 2 and submit that value on view 3..
Here Is the code of 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" />
And on View 3 i am submitting all the values
Here is the code of Button_click on 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;
}
I tried to Wrap up code in Update Panel but it is not working.
回答1:
i have found solution myself , as i am storing the file as HttpPostedFile
on session while changing the view
protected void activeView2(object sender, EventArgs e)
{
multiview.ActiveViewIndex = 2;
// storing uploaded file into sessin view HttpPostedFile
HttpPostedFile file = drFileUpload.PostedFile;
Session["f1"] = file;
}
And on Submit I am retrieving that 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;
}
}
Hope This will help someone in future
来源:https://stackoverflow.com/questions/34173548/file-upload-inside-multi-view-always-shows-fileuplode-hasfiles-false