Link to home
Start Free TrialLog in
Avatar of kennysflau

asked on

About httppostedfile

Hi experts,

I have a webform wich contains a httppostedfile to upload file. I also have several dropdownlists on the page which will trigger auto-postback event.

My problem is, when the postback event is triggered, the text in the "textbos" of the httppostedfile will disappeared. I've already set the enable viewstate to true, however, the text still disappeared.

Could anyone tell me how to solve the problem?

Many thanks!!!

Avatar of TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kennysflau


So is there any other way to achieve my purpose? Maybe I can use some tools other than httppostedfile? Or just "hide" the "textbox" but only show the "browse" button, and create a real textbox myself to save the link? Or else?


I don't know about other controls, there are certainly none in the standard toolset that would behave any differently. The problem with hiding the textbox is that you cannot populate this value even if you store it elsewhere, this is by design to prevent a server from deliberately uploading a specific file from your machine without your intervention.

What is the page actually trying to do? It may be possible to redesign slightly to achieve the desired aim.

So how about if it is a must to keep the post back event? Is there any other tricky way to get it done? It's not a problem that the "textbox" doesn't contain the link. I mean, maybe I can store the link somewhere else and use it to call the httpPostedFile.SaveAs? Is is possible?

Well that is why I was wondering exactly what the page is doing. If for example your dropdowns are used to categorise the file being uploaded then you could simply hide the upload control until the various dropdowns have been populated. Then with a little bit of javascript for example, show the upload control and do the final postback. In a way you are improving the interface then because you do not get to choose the file until you have completed the categorisation. A kind of built-in check that everything is complete. Of course this may not be the purpose of your page but hopefully you get the idea.

well... it is used for categorization but not for the file upload. So I guess it's really a must to redesign the interface....
Avatar of Chinmay Patel
Hi There,

There is a simple way to solve your problem. I am not sure whether you will like it or not but as per my experience with File Upload Control, if you postback, the data is going to be lost so what I suggest here is you seperate your dropdowns and your File Upload control and then use frames/iframes to load them, this way they'll work independantly or else you can do it this way, or else you can keep that file upload control disabled until the categorization is done using Server/Client side code.