Uploading file input clearing on postback | | |
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 | | | | re: Uploading file input clearing on postback
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.
"tshad" <tscheiderich@ftsolutions.com> wrote in message
news:OfR0TRUxFHA.2652@TK2MSFTNGP14.phx.gbl...[color=blue]
>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
>[/color] | | | | re: Uploading file input clearing on postback
"Peter Rilling" <peter@nospam.rilling.net> wrote in message
news:%23nft5uUxFHA.2076@TK2MSFTNGP14.phx.gbl...[color=blue]
>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.[/color]
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(HttpApplica tion app) +340
NFission.WebControls.ScrollKeeperModule.context_Be ginRequest(Object
sender, EventArgs e) +33
System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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[color=blue]
>
> "tshad" <tscheiderich@ftsolutions.com> wrote in message
> news:OfR0TRUxFHA.2652@TK2MSFTNGP14.phx.gbl...[color=green]
>>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
>>[/color]
>
>[/color] | | | | re: Uploading file input clearing on postback
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" <tscheiderich@ftsolutions.com> wrote in message
news:OZ8O1TVxFHA.1284@tk2msftngp13.phx.gbl...[color=blue]
> "Peter Rilling" <peter@nospam.rilling.net> wrote in message
> news:%23nft5uUxFHA.2076@TK2MSFTNGP14.phx.gbl...[color=green]
>>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.[/color]
>
> 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(HttpApplica tion app) +340
> NFission.WebControls.ScrollKeeperModule.context_Be ginRequest(Object
> sender, EventArgs e) +33
>
> System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
> +60
> System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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[color=green]
>>
>> "tshad" <tscheiderich@ftsolutions.com> wrote in message
>> news:OfR0TRUxFHA.2652@TK2MSFTNGP14.phx.gbl...[color=darkred]
>>>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
>>>[/color]
>>
>>[/color]
>
>[/color] | | | | re: Uploading file input clearing on postback
"Peter Rilling" <peter@nospam.rilling.net> wrote in message
news:uOBgKXWxFHA.2348@TK2MSFTNGP15.phx.gbl...[color=blue]
> 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.[/color]
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[color=blue]
>
> "tshad" <tscheiderich@ftsolutions.com> wrote in message
> news:OZ8O1TVxFHA.1284@tk2msftngp13.phx.gbl...[color=green]
>> "Peter Rilling" <peter@nospam.rilling.net> wrote in message
>> news:%23nft5uUxFHA.2076@TK2MSFTNGP14.phx.gbl...[color=darkred]
>>>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.[/color]
>>
>> 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(HttpApplica tion app) +340
>> NFission.WebControls.ScrollKeeperModule.context_Be ginRequest(Object
>> sender, EventArgs e) +33
>>
>> System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
>> +60
>> System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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[color=darkred]
>>>
>>> "tshad" <tscheiderich@ftsolutions.com> wrote in message
>>> news:OfR0TRUxFHA.2652@TK2MSFTNGP14.phx.gbl...
>>>>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
>>>>
>>>
>>>[/color]
>>
>>[/color]
>
>[/color] | | | | re: Uploading file input clearing on postback
"tshad" <tscheiderich@ftsolutions.com> wrote in message
news:ur$abQdxFHA.2008@TK2MSFTNGP10.phx.gbl...[color=blue]
> "Peter Rilling" <peter@nospam.rilling.net> wrote in message
> news:uOBgKXWxFHA.2348@TK2MSFTNGP15.phx.gbl...[color=green]
>> 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.[/color]
>
> 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.[/color]
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[color=blue]
>
> Thanks,
>
> Tom[color=green]
>>
>> "tshad" <tscheiderich@ftsolutions.com> wrote in message
>> news:OZ8O1TVxFHA.1284@tk2msftngp13.phx.gbl...[color=darkred]
>>> "Peter Rilling" <peter@nospam.rilling.net> wrote in message
>>> news:%23nft5uUxFHA.2076@TK2MSFTNGP14.phx.gbl...
>>>>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(HttpApplica tion app) +340
>>> NFission.WebControls.ScrollKeeperModule.context_Be ginRequest(Object
>>> sender, EventArgs e) +33
>>>
>>> System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
>>> +60
>>> System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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
>>>>
>>>> "tshad" <tscheiderich@ftsolutions.com> wrote in message
>>>> news:OfR0TRUxFHA.2652@TK2MSFTNGP14.phx.gbl...
>>>>>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
>>>>>
>>>>
>>>>
>>>
>>>[/color]
>>
>>[/color]
>
>[/color] | | | | re: Uploading file input clearing on postback
"tshad" <tscheiderich@ftsolutions.com> wrote in message
news:%23V66yUdxFHA.2504@TK2MSFTNGP10.phx.gbl...[color=blue]
> "tshad" <tscheiderich@ftsolutions.com> wrote in message
> news:ur$abQdxFHA.2008@TK2MSFTNGP10.phx.gbl...[color=green]
>> "Peter Rilling" <peter@nospam.rilling.net> wrote in message
>> news:uOBgKXWxFHA.2348@TK2MSFTNGP15.phx.gbl...[color=darkred]
>>> 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.[/color][/color][/color]
I tried that and it works.
[color=blue][color=green]
>>
>> 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.[/color]
>
> 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.[/color]
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[color=blue]
>
> Tom[color=green]
>>
>> Thanks,
>>
>> Tom[color=darkred]
>>>
>>> "tshad" <tscheiderich@ftsolutions.com> wrote in message
>>> news:OZ8O1TVxFHA.1284@tk2msftngp13.phx.gbl...
>>>> "Peter Rilling" <peter@nospam.rilling.net> wrote in message
>>>> news:%23nft5uUxFHA.2076@TK2MSFTNGP14.phx.gbl...
>>>>>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(HttpApplica tion app) +340
>>>> NFission.WebControls.ScrollKeeperModule.context_Be ginRequest(Object
>>>> sender, EventArgs e) +33
>>>>
>>>> System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
>>>> +60
>>>> System.Web.HttpApplication.ExecuteStep(IExecutionS tep 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
>>>>>
>>>>> "tshad" <tscheiderich@ftsolutions.com> wrote in message
>>>>> news:OfR0TRUxFHA.2652@TK2MSFTNGP14.phx.gbl...
>>>>>>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
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>[/color]
>>
>>[/color]
>
>[/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|