value="" option on input type="file" in ASP.NET

Discussion in 'ASP .Net' started by IkBenHet, Jun 28, 2005.

  1. IkBenHet

    IkBenHet Guest

    Hello,

    I am uploading a file using this form in ASP.NET. I have also added a
    simpel textfield:
    <form runat="server" enctype="multipart/form-data">
    <input type="file" id="oFile" Name="oFile" size="70" runat="Server">
    <input type="text" SIZE="20" MAXLENGTH="20" id="Name" NAME="Name">
    <input type="submit" id="Submit" runat="Server" value="Submit"
    OnServerClick="SubmitButton_Click">
    </form>

    I want to do some validation on the textfield "Name". When for example
    the field is not filled in or does not contain the correct value, I
    want is come back to the form with an error message and already fill in
    the previous submitted values (so the user does not need to fill in the
    complete form again). No problem so far.

    The problem starts when I return to the form and then want to pass the
    submitted path back to the oFile field. Something like: <input
    type="file" id="oFile" Name="oFile" size="70" runat="Server"
    value="<%=sPostedFilePatch%>">

    It seems to be impossible to set the "value" option for a input field
    with type="file".

    How can I make sure that user does NOT have to browse for the file
    again when another field than the "oFile" field has a incorrect value.

    Thanks
    IkBenHet, Jun 28, 2005
    #1
    1. Advertising

  2. IkBenHet

    Hans Kesting Guest

    IkBenHet wrote:
    > Hello,
    >
    > I am uploading a file using this form in ASP.NET. I have also added a
    > simpel textfield:
    > <form runat="server" enctype="multipart/form-data">
    > <input type="file" id="oFile" Name="oFile" size="70" runat="Server">
    > <input type="text" SIZE="20" MAXLENGTH="20" id="Name" NAME="Name">
    > <input type="submit" id="Submit" runat="Server" value="Submit"
    > OnServerClick="SubmitButton_Click">
    > </form>
    >
    > I want to do some validation on the textfield "Name". When for example
    > the field is not filled in or does not contain the correct value, I
    > want is come back to the form with an error message and already fill
    > in the previous submitted values (so the user does not need to fill
    > in the complete form again). No problem so far.
    >
    > The problem starts when I return to the form and then want to pass the
    > submitted path back to the oFile field. Something like: <input
    > type="file" id="oFile" Name="oFile" size="70" runat="Server"
    > value="<%=sPostedFilePatch%>">
    >
    > It seems to be impossible to set the "value" option for a input field
    > with type="file".
    >
    > How can I make sure that user does NOT have to browse for the file
    > again when another field than the "oFile" field has a incorrect value.
    >
    > Thanks


    Try to remove the "runat=server". As a security precaution, you *can't* set
    the value for a fileinput.

    Hans Kesting
    Hans Kesting, Jun 28, 2005
    #2
    1. Advertising

  3. IkBenHet

    Patrice Guest

    You can't set programmatically this value for safety reasons (it would allow
    to pick files on client machine without the user permission).

    Possible workarounds :
    - change the UI
    - validate client side
    - validate server side without refreshing the page (IFRAME, XMLHTTP)
    - others ?

    Patrice

    --

    "IkBenHet" <> a écrit dans le message de
    news:...
    > Hello,
    >
    > I am uploading a file using this form in ASP.NET. I have also added a
    > simpel textfield:
    > <form runat="server" enctype="multipart/form-data">
    > <input type="file" id="oFile" Name="oFile" size="70" runat="Server">
    > <input type="text" SIZE="20" MAXLENGTH="20" id="Name" NAME="Name">
    > <input type="submit" id="Submit" runat="Server" value="Submit"
    > OnServerClick="SubmitButton_Click">
    > </form>
    >
    > I want to do some validation on the textfield "Name". When for example
    > the field is not filled in or does not contain the correct value, I
    > want is come back to the form with an error message and already fill in
    > the previous submitted values (so the user does not need to fill in the
    > complete form again). No problem so far.
    >
    > The problem starts when I return to the form and then want to pass the
    > submitted path back to the oFile field. Something like: <input
    > type="file" id="oFile" Name="oFile" size="70" runat="Server"
    > value="<%=sPostedFilePatch%>">
    >
    > It seems to be impossible to set the "value" option for a input field
    > with type="file".
    >
    > How can I make sure that user does NOT have to browse for the file
    > again when another field than the "oFile" field has a incorrect value.
    >
    > Thanks
    >
    Patrice, Jun 28, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cas
    Replies:
    5
    Views:
    782
    Kevin Jones
    Aug 28, 2006
  2. Daniel Rudy
    Replies:
    5
    Views:
    1,240
    Jukka K. Korpela
    Aug 23, 2008
  3. Roberto
    Replies:
    3
    Views:
    298
  4. Susan Cranford
    Replies:
    2
    Views:
    392
  5. Tarkeshwar
    Replies:
    2
    Views:
    183
Loading...

Share This Page