Monday, March 26, 2012

UpdatePanel & Wizard together ERROR

I have a Wizard control inside of the UpdatePanel control. In the Wizard control, I have a FileUpload control. WHen I set the ScriptManager to enable Partial Rending, I get this error message when I tried to upload the file:

"Object reference not set to an instance of an object"

This is the culprit:

int imageSize = fileuploader.PostedFile.ContentLength;

Because fileuploader is NULL.

Why does this happen? Does the page not instantiate a fileupload object when the whole page is not rendered?

thanks!

Lots of threads on this issue ... Unfortunately you can't use a FileUpload control inside of an update panel. FileUploading, in general, has always been a thorny issue. The form has has to do an HTTP post to include the bytes of the file selected by the user. No indication that this can (or should) be fixed.

With a normal "full" form postback, the browser (running natively on the operating system of the host system) is able to obtain the binary of the file selected by the user and push those bytes to the server in an HTTP POST.

Allowing arbitrary JavaScript to perform the same operation -- whether it's Atlas or any other Ajax framework -- would violoate the security lockdowns that most modern browsers *must* enforce. If JavaScript was able to programmatically probe the local file system of the user and upload binary data to a server, an entirely new/old form of exploits would be enabled.

It's for the similar reasons that you can't programmatically set the default file that you'd like to upload in the web page. Use of FileUpload and the underlying HTML tags requires an "act of comission" on the part of the user. If this was not enforced by the browser, a malicious web page could data-mine arbitrary local storage w/out any knowledge/awareness of the user.

What should work would be to render in a asp:Literal control the raw HTML <input type="file" .../> tag. Going down this path would require that you manually implement an ASPX file that can accept the resulting HTTP post and process the response -- exactly what the FileUpload control is actually doing under the covers.
After many hours of trying to get a fileUpload control to work from inside an update panel i discovered that it isn't possible.

However, from all that I can gather, it should work from outside anupdate panel, even if there is a different update panel on the page?

Can someone confirm for me that this is the case?

Many Thanks,
Dave

hello.

yes, this is the case. the upload control should work when pleced outside the updatepanel.


what if the FileUpload component is inside an iframe inside an update panel?would it help to trigger an full page postback?

As I know that the popup control is using an iframe, please try if u guys still want to...


I think you should take a look by overwritting the methods loadControlState and savecontrolstate, to maintain the fileupload's state. I am a newbie, but maybe it could work.

No comments:

Post a Comment