Avatar of kennysflau
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!!!

Kenny
ASP.NET

Avatar of undefined
Last Comment
Chinmay Patel

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
TimCottee

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
kennysflau

ASKER
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?

Thanks!
TimCottee

kennysflau,

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.

Tim
kennysflau

ASKER
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?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
TimCottee

kennysflau,

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.

Tim
kennysflau

ASKER
well... it is used for categorization but not for the file upload. So I guess it's really a must to redesign the interface....
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.

Regards,
Chinmay
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.