Uploading file input clearing on postback

T

tshad

I have an upload file input as:
<input id="MyFile" style="width:300px" type="File" runat="Server">

This works fine, but I find that if my page doesn't pass validation during
postback, the page comes back with all the data intact, except for the
upload object. The text box for "MyFile" (my example) is always cleared.

Why is that and is there a way to stop that from happening?

Thanks,

Tom
 
P

Peter Rilling

I don't think the browser will let you set the value for that field. What
you might want to do is to cache the file during the first submit. Keep in
mind that the file is always uploaded, even if validation fails, so it might
improve response time after the first failure if the user does not have to
upload the file again.
 
T

tshad

Peter Rilling said:
I don't think the browser will let you set the value for that field. What
you might want to do is to cache the file during the first submit. Keep in
mind that the file is always uploaded, even if validation fails, so it
might improve response time after the first failure if the user does not
have to upload the file again.

That may answer another question that has been driving me crazy today.

I need to check to see if the file size is too large.

The problem is I can't seem to stop it from trying to load the file and then
giving me an error page

***********************************************************************************
Maximum request length exceeded.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Maximum request length
exceeded.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.GetEntireRawContent() +895
System.Web.HttpRequest.GetMultipartContent() +58
System.Web.HttpRequest.FillInFormCollection() +255
System.Web.HttpRequest.get_Form() +50
NFission.WebControls.Config.EnablePage(HttpApplication app) +340
NFission.WebControls.ScrollKeeperModule.context_BeginRequest(Object
sender, EventArgs e) +33
System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87


*********************************************************************************************************************

I can't seem to stop it. There doesn't seem to be anywhere to put my
try/catch block. I tried putting it around my upload routing that I call
when I do my submit. That is the point at which I look for the size of the
file.

But that doesn't seem to matter.

I have literally ripped out that code (and any that refers to my upload
objects ID).

<input id="MyFile" style="width:300px" type="File" runat="Server">

and now my submit buttons event does nothing:

Sub SaveChanges_Click(s as Object, e as ImageClickEventArgs)
End Sub

And it still tries to load the file when I hit the submit button.

Why and how can I test for the size of the file to give the user a warning
that the file is too large?

Thanks,

Tom
 
P

Peter Rilling

Well, you cannot check the size because your code does not get invoked until
the entire file is downloaded. You can increase the max size by changing
the maxRequestLength attribute in the machine.config.

One thing I have never done, but you can try, is to see if the error event
in the global.asax can trap that error.

tshad said:
Peter Rilling said:
I don't think the browser will let you set the value for that field. What
you might want to do is to cache the file during the first submit. Keep
in mind that the file is always uploaded, even if validation fails, so it
might improve response time after the first failure if the user does not
have to upload the file again.

That may answer another question that has been driving me crazy today.

I need to check to see if the file size is too large.

The problem is I can't seem to stop it from trying to load the file and
then giving me an error page

***********************************************************************************
Maximum request length exceeded.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Maximum request length
exceeded.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.GetEntireRawContent() +895
System.Web.HttpRequest.GetMultipartContent() +58
System.Web.HttpRequest.FillInFormCollection() +255
System.Web.HttpRequest.get_Form() +50
NFission.WebControls.Config.EnablePage(HttpApplication app) +340
NFission.WebControls.ScrollKeeperModule.context_BeginRequest(Object
sender, EventArgs e) +33

System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87


*********************************************************************************************************************

I can't seem to stop it. There doesn't seem to be anywhere to put my
try/catch block. I tried putting it around my upload routing that I call
when I do my submit. That is the point at which I look for the size of
the file.

But that doesn't seem to matter.

I have literally ripped out that code (and any that refers to my upload
objects ID).

<input id="MyFile" style="width:300px" type="File" runat="Server">

and now my submit buttons event does nothing:

Sub SaveChanges_Click(s as Object, e as ImageClickEventArgs)
End Sub

And it still tries to load the file when I hit the submit button.

Why and how can I test for the size of the file to give the user a warning
that the file is too large?

Thanks,

Tom
 
T

tshad

Peter Rilling said:
Well, you cannot check the size because your code does not get invoked
until the entire file is downloaded. You can increase the max size by
changing the maxRequestLength attribute in the machine.config.

One thing I have never done, but you can try, is to see if the error event
in the global.asax can trap that error.

I'll try that, but I know that there is nowhere (that I can find) to
surround some code with a try/catch block to catch the error.

As a matter of fact, the error seems to be coming from somewhere else than
the normal error page you get.

Normally, if I have my trace on, I can still the traces below with my
objects and trace statements. Not so with this error page. You get the
error page only and non of your trace statements, so you can't even tell how
far you've gotten.

This can be a real problem if the downloading of the file is done while the
other code is being processed.

My question would be, does it happen before the Page_Load function?

If not, you could be in the middle of processing your page and you get this
random error page that stops the processing. The problem is you don't know
where you got to.

Thanks,

Tom
tshad said:
Peter Rilling said:
I don't think the browser will let you set the value for that field.
What you might want to do is to cache the file during the first submit.
Keep in mind that the file is always uploaded, even if validation fails,
so it might improve response time after the first failure if the user
does not have to upload the file again.

That may answer another question that has been driving me crazy today.

I need to check to see if the file size is too large.

The problem is I can't seem to stop it from trying to load the file and
then giving me an error page

***********************************************************************************
Maximum request length exceeded.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Maximum request length
exceeded.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.GetEntireRawContent() +895
System.Web.HttpRequest.GetMultipartContent() +58
System.Web.HttpRequest.FillInFormCollection() +255
System.Web.HttpRequest.get_Form() +50
NFission.WebControls.Config.EnablePage(HttpApplication app) +340
NFission.WebControls.ScrollKeeperModule.context_BeginRequest(Object
sender, EventArgs e) +33

System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87


*********************************************************************************************************************

I can't seem to stop it. There doesn't seem to be anywhere to put my
try/catch block. I tried putting it around my upload routing that I call
when I do my submit. That is the point at which I look for the size of
the file.

But that doesn't seem to matter.

I have literally ripped out that code (and any that refers to my upload
objects ID).

<input id="MyFile" style="width:300px" type="File" runat="Server">

and now my submit buttons event does nothing:

Sub SaveChanges_Click(s as Object, e as ImageClickEventArgs)
End Sub

And it still tries to load the file when I hit the submit button.

Why and how can I test for the size of the file to give the user a
warning that the file is too large?

Thanks,

Tom
I have an upload file input as:
<input id="MyFile" style="width:300px" type="File" runat="Server">

This works fine, but I find that if my page doesn't pass validation
during postback, the page comes back with all the data intact, except
for the upload object. The text box for "MyFile" (my example) is
always cleared.

Why is that and is there a way to stop that from happening?

Thanks,

Tom
 
T

tshad

tshad said:
I'll try that, but I know that there is nowhere (that I can find) to
surround some code with a try/catch block to catch the error.

As a matter of fact, the error seems to be coming from somewhere else than
the normal error page you get.

Normally, if I have my trace on, I can still the traces below with my
objects and trace statements. Not so with this error page. You get the
error page only and non of your trace statements, so you can't even tell
how far you've gotten.

This can be a real problem if the downloading of the file is done while
the other code is being processed.

My question would be, does it happen before the Page_Load function?

If not, you could be in the middle of processing your page and you get
this random error page that stops the processing. The problem is you
don't know where you got to.

Another problem here is that I would want to capture the error so that I can
put a message on the screen telling the user that his file was too big.
This would allow him to upload a different file, without losing all the
input he has already put in. If I go to an error page, all that data is
lost.

Tom
Thanks,

Tom
tshad said:
I don't think the browser will let you set the value for that field.
What you might want to do is to cache the file during the first submit.
Keep in mind that the file is always uploaded, even if validation fails,
so it might improve response time after the first failure if the user
does not have to upload the file again.

That may answer another question that has been driving me crazy today.

I need to check to see if the file size is too large.

The problem is I can't seem to stop it from trying to load the file and
then giving me an error page

***********************************************************************************
Maximum request length exceeded.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Maximum request length
exceeded.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.GetEntireRawContent() +895
System.Web.HttpRequest.GetMultipartContent() +58
System.Web.HttpRequest.FillInFormCollection() +255
System.Web.HttpRequest.get_Form() +50
NFission.WebControls.Config.EnablePage(HttpApplication app) +340
NFission.WebControls.ScrollKeeperModule.context_BeginRequest(Object
sender, EventArgs e) +33

System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87


*********************************************************************************************************************

I can't seem to stop it. There doesn't seem to be anywhere to put my
try/catch block. I tried putting it around my upload routing that I
call when I do my submit. That is the point at which I look for the
size of the file.

But that doesn't seem to matter.

I have literally ripped out that code (and any that refers to my upload
objects ID).

<input id="MyFile" style="width:300px" type="File" runat="Server">

and now my submit buttons event does nothing:

Sub SaveChanges_Click(s as Object, e as ImageClickEventArgs)
End Sub

And it still tries to load the file when I hit the submit button.

Why and how can I test for the size of the file to give the user a
warning that the file is too large?

Thanks,

Tom

I have an upload file input as:
<input id="MyFile" style="width:300px" type="File" runat="Server">

This works fine, but I find that if my page doesn't pass validation
during postback, the page comes back with all the data intact, except
for the upload object. The text box for "MyFile" (my example) is
always cleared.

Why is that and is there a way to stop that from happening?

Thanks,

Tom
 
T

tshad

I tried that and it works.
Another problem here is that I would want to capture the error so that I
can put a message on the screen telling the user that his file was too
big. This would allow him to upload a different file, without losing all
the input he has already put in. If I go to an error page, all that data
is lost.

This one is a real problem

The problem is that the user may not realize that the field has been cleared
out after he gets a validation error on one of the other fields and then
think that the file was upload, when in fact it wasn't.

Tom
Tom
Thanks,

Tom
I don't think the browser will let you set the value for that field.
What you might want to do is to cache the file during the first submit.
Keep in mind that the file is always uploaded, even if validation
fails, so it might improve response time after the first failure if the
user does not have to upload the file again.

That may answer another question that has been driving me crazy today.

I need to check to see if the file size is too large.

The problem is I can't seem to stop it from trying to load the file and
then giving me an error page

***********************************************************************************
Maximum request length exceeded.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Maximum request length
exceeded.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.GetEntireRawContent() +895
System.Web.HttpRequest.GetMultipartContent() +58
System.Web.HttpRequest.FillInFormCollection() +255
System.Web.HttpRequest.get_Form() +50
NFission.WebControls.Config.EnablePage(HttpApplication app) +340
NFission.WebControls.ScrollKeeperModule.context_BeginRequest(Object
sender, EventArgs e) +33

System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87


*********************************************************************************************************************

I can't seem to stop it. There doesn't seem to be anywhere to put my
try/catch block. I tried putting it around my upload routing that I
call when I do my submit. That is the point at which I look for the
size of the file.

But that doesn't seem to matter.

I have literally ripped out that code (and any that refers to my upload
objects ID).

<input id="MyFile" style="width:300px" type="File" runat="Server">

and now my submit buttons event does nothing:

Sub SaveChanges_Click(s as Object, e as ImageClickEventArgs)
End Sub

And it still tries to load the file when I hit the submit button.

Why and how can I test for the size of the file to give the user a
warning that the file is too large?

Thanks,

Tom

I have an upload file input as:
<input id="MyFile" style="width:300px" type="File" runat="Server">

This works fine, but I find that if my page doesn't pass validation
during postback, the page comes back with all the data intact, except
for the upload object. The text box for "MyFile" (my example) is
always cleared.

Why is that and is there a way to stop that from happening?

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top