在.net C#中上传文件 [英] file uploading in .net c#

查看:78
本文介绍了在.net C#中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在页面加载事件中使用过文件上传控制和编写代码来上传文件.但是当我提交表单并转到下一页时,他们的iam单击返回按钮来到了第一页.第一次返回该文件时,我返回时仍要求我上载该文件.有什么解决方案,以便它应保存我上载的较早文件,而不再要求我再次上载该文件.

Hi all I have used fileupload control and written code to upload the file in my page load event.But when i submit the form and go to next page and their iam clicking back button to come to the first page.Although i uploaded the file first time it is still asking me upload the file when i return back.What is the solution so that it should save the earlier file which i uploaded and should not ask me again to upload the file.

推荐答案

您只需要维护上传状态.如果并且一旦上传了文件,请保留会话标志,例如Session["IsUploaded"] = true;

现在,在检查上传之前,您所需要做的就是首先查看此Session字段的值.如果您将其设置为true,则通过验证/确认检查并转到下一页.

更新:
我重新阅读了问题,听起来您在客户端进行了验证检查. (因为您说的是浏览器后退按钮的情况). 浏览器后退"按钮可在浏览器缓存上使用,并且除非询问,否则不会重新加载页面.重新加载页面,或者保持标记跟踪客户端的上传,并在上传后对其进行更新.试一试哪个最适合您.
You simply need to maintain the state of the upload. If and once you upload a file, keep a session flag like Session["IsUploaded"] = true;

Now, before checking for the upload, all you need is to see the value of this Session field first. If you find it as set true, then pass on the verification/validation check and move on to next page.

UPDATE:
I re-read the question and it sounded like you have the validation check on client side. (since you said it is the case of browser back button). Browser back button works on browsers cache and the page is not reloaded until asked. Either reload the page or keep the flag tracking the upload on client side and update it once uploaded. Try out which one works for you.


vijay,

您的问题是页面回发,因此一旦检查以下内容就是页面加载

如果(!IsPostBack)

并且最好将您的文件上传从页面加载更改为其他事件.


祝您生日快乐... :)

Seshu
Hi vijay,

your problem is page post back so once check the following is page load

if (!IsPostBack)

and also better to change ur file upload from page load to some other event.


Happy Codding...:)

Seshu


这篇关于在.net C#中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆