I am having Gridivew with fileupload which has Add more rows operation. When i Click on Add more rows the fileupload control loses the file. I need to save all the added rows on a single submit button which should save all the files on a folder. Kindly help me.
我正在使用带有fileupload的Gridivew,它具有添加更多行操作。当我单击添加更多行时,fileupload控件将丢失该文件。我需要将所有添加的行保存在单个提交按钮上,该按钮应保存文件夹上的所有文件。请帮助我。
Thanks in advance
提前致谢
1 个解决方案
#1
You cannot persist the input type="file"
state after an HTTPPost. ( In ASP.NET jargon this will translate as cannot persist asp:FileUpload
s value after PostBack ).
在HTTPPost之后,您无法保持输入类型=“文件”状态。 (在ASP.NET术语中,这将转换为无法在PostBack之后保持asp:FileUploads值)。
Its designed that way to address security issues. There are so many examples of the same question answered here at * ( search it ). There is a Session
hack that provides a workaround but its for single file. Link here: https://*.com/a/18656681/17447
它旨在解决安全问题。 *上有很多相同问题的例子(搜索它)。有一个会话黑客提供了一个解决方法,但它的单个文件。链接到这里:https://*.com/a/18656681/17447
Theoretically you could still do it using a Dictionary<int, FileUpload>
. The first parameter will the GridViewRow.RowIndex
and the second parameter would be the asp:FileUpload
control on that row. You can start by adding all rows at the first PostBack to a session and then updating it when file.HasFile and so. But IMHO, don't do that because
从理论上讲,你仍然可以使用Dictionary
- Its extremely complicated.
- Bad UX, it confuses the user. He wont know if there really is a file.
- Clutters the ViewState immensely.
它非常复杂。
糟糕的用户体验,它会让用户感到困惑。他不知道是否真的有档案。
极大地破坏了ViewState。
So these are the things you can do,
所以这些是你可以做的事情,
- Prompt the user that files will be lost when they click to add the files by asking their confirmation.
- Put a textbox and button asking user to pre-enter the number of files they want to add.
- Use a third party plugin that use ajax to add rows.(jqGrid and datatables.net are good.)
提示用户在单击添加文件时通过询问确认文件将丢失。
放置一个文本框和按钮,要求用户预先输入要添加的文件数。
使用第三方插件使用ajax添加行。(jqGrid和datatables.net很好。)
#1
You cannot persist the input type="file"
state after an HTTPPost. ( In ASP.NET jargon this will translate as cannot persist asp:FileUpload
s value after PostBack ).
在HTTPPost之后,您无法保持输入类型=“文件”状态。 (在ASP.NET术语中,这将转换为无法在PostBack之后保持asp:FileUploads值)。
Its designed that way to address security issues. There are so many examples of the same question answered here at * ( search it ). There is a Session
hack that provides a workaround but its for single file. Link here: https://*.com/a/18656681/17447
它旨在解决安全问题。 *上有很多相同问题的例子(搜索它)。有一个会话黑客提供了一个解决方法,但它的单个文件。链接到这里:https://*.com/a/18656681/17447
Theoretically you could still do it using a Dictionary<int, FileUpload>
. The first parameter will the GridViewRow.RowIndex
and the second parameter would be the asp:FileUpload
control on that row. You can start by adding all rows at the first PostBack to a session and then updating it when file.HasFile and so. But IMHO, don't do that because
从理论上讲,你仍然可以使用Dictionary
- Its extremely complicated.
- Bad UX, it confuses the user. He wont know if there really is a file.
- Clutters the ViewState immensely.
它非常复杂。
糟糕的用户体验,它会让用户感到困惑。他不知道是否真的有档案。
极大地破坏了ViewState。
So these are the things you can do,
所以这些是你可以做的事情,
- Prompt the user that files will be lost when they click to add the files by asking their confirmation.
- Put a textbox and button asking user to pre-enter the number of files they want to add.
- Use a third party plugin that use ajax to add rows.(jqGrid and datatables.net are good.)
提示用户在单击添加文件时通过询问确认文件将丢失。
放置一个文本框和按钮,要求用户预先输入要添加的文件数。
使用第三方插件使用ajax添加行。(jqGrid和datatables.net很好。)