ASP.NET回发后保留fileupload [英] ASP.NET Keep fileupload after postback

查看:307
本文介绍了ASP.NET回发后保留fileupload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VB.NET编写一个Intranet ASP.NET页面。我遇到了一个处理文件上传的特别讨厌的问题。我会尽我所能解释的问题,也许有人可以帮助。

我的问题几乎是,或者这一个,除了(文件名除外)我不在乎发送文件到服务器,直到其他数据已经审查。

下面是情况:

Joe Q. Dataentry将一些数据输入到几个字段中。前3个是下拉菜单,当他改变选择时,会触发一个回发事件来查询数据库中其他下拉选择的有效条目。选择这些值后,他输入一些其他数据,选择一个文件陪伴数据,然后点击更新按钮。当他点击按钮时,会触发一个回发事件,将当前数据发送到服务器进行验证。数据会在数据库中产生一个变化,所以他会看到当前的状态,以及当他做出更改时的样子。他现在可以确定或取消操作,无论出于何种原因。

他将看到的部分数据涉及到可能是PDF的文件的扩展,或者也可能是一些图像文件或其他文件。

现在这里是我的问题所在 - 在每个回发事件,文件上传对话框被清除。我通过创建一个临时文件在第一个回发,然后重命名,如果他点击确定或删除取消...,但我需要做的各种事情,基于以前的数据和文件名的状态。我试图保留一些会话变量来保留文件名,这只是重命名文件的工作正常,但我需要做的事情变得笨拙。



我想要做的是能够让回发事件呈现更改,然后当用户单击确定,然后提交文件。有没有办法做到这一点?

我的一个想法是做一些验证客户端(我已经重新验证服务器端,所以我不太担心那里的数据安全),但我不知道如何从数据库查询中获取信息。



感谢您的帮助,并阅读我稍微复杂的故事/情况! p>




编辑

我想要做的是防止某个按钮发射完整的回发。有没有办法做到这一点?



编辑二:

在页面上有一个更新面板 - 是否有任何方法让按钮只发布更新面板中的内容?

解决方案

你可能想要做的是把你的下拉列表放在一个ASP.NET AJAX UpdatePanel中,并保持你的文件上传控制。

您的更新面板将执行回发功能,并允许验证逻辑在不提交文件的情况下发生,然后当您点击最后一个保存按钮时(这也是外部你的UpdatePanel)整个表单将被提交回来,你可以使用你的文件。


I'm writing an intranet ASP.NET page using VB.NET. I've run into a particularly nasty problem dealing with handling file uploads. I'll do my best to explain the problem, and perhaps someone can help.

My problem is almost a duplicate of this one, or this one, except (other than the filename) I don't care about sending the file to the server until the other data has been reviewed.

Here's the situation:

Joe Q. Dataentry inputs some data into several fields. The first 3 are drop down, and when he changes the selection, a postback event is fired that queries a database for valid entries for the other drop down selections. After selecting the values, he inputs some other data, chooses a file to accompany the data and clicks the "Update" button. When he hits the button, it fires a postback event that sends the current data to the server to be validated. The data will create a change in the database, so he is presented with a view of the current state, and what it will look like when his changes are made. He can now either confirm or cancel the operation for whatever reason.

Part of the data he will see involves the extension of the file which may be a PDF, or could also be some image file or other document.

Now here's where my problem is - on each postback event, the fileupload dialog is cleared. I was getting around it by creating a temporary file on the first postback and then renaming if he clicks OK or deleting on Cancel... but I need to do a variety of things, based on the previous state of data and the filename. I've tried to keep some session variables to retain the filename, and that works OK for just renaming the file, but for what I need to do it gets unwieldy.

What I want to do is be able to have the postback event to present the changes, and then when the user clicks "OK", submit the file. Is there any possible way to do that?

One of my thoughts was to do some of the validation client-side (I'm already re-validating server side so I'm not too worried about data security there), but I don't know how I could get the information from the database query.

Thanks for any help, and reading my slightly convoluted story/situation!


EDIT:

It appears that what I want to do is prevent a certain button from firing a full postback. Is there any way to do that?

EDIT II:

I have an update panel on the page already - is there any way for the button to only post what's in the update panel?

解决方案

What you might want to do is place your drop-downs inside of an ASP.NET AJAX UpdatePanel, and keep your file upload control out of that.

Your update panel will do the post backs and allow your validation logic to happen without submitting the file, then when you hit your final "Save" button (which is also outside of your UpdatePanel) the entire form will be submitted back and you can work with your file then.

这篇关于ASP.NET回发后保留fileupload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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