Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Html File Field

Html File Field

Scheduled Pinned Locked Moved ASP.NET
htmlhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Program err
    wrote on last edited by
    #1

    I dont want the user to type the path of the file in the "Html File Field" manually. I want user to enter file path using browse button only ! Kindly help !:)

    A M 2 Replies Last reply
    0
    • P Program err

      I dont want the user to type the path of the file in the "Html File Field" manually. I want user to enter file path using browse button only ! Kindly help !:)

      A Offline
      A Offline
      atul_moghe
      wrote on last edited by
      #2

      hi, try this. u can have the serverclick event of this control in ur codebehind. Private Sub btnImport_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.ServerClick and in tht u can write importFile.PostedFile.FileName to get the file name tht is selected by user. hope this will help u out. happy coding !!! A R Moghe.

      1 Reply Last reply
      0
      • P Program err

        I dont want the user to type the path of the file in the "Html File Field" manually. I want user to enter file path using browse button only ! Kindly help !:)

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        Hi there, To disallow the user to type or paste a value to the textbox of the input file element, you simply create event handlers for the onkeypress and onpaste events and cancel the events:

        <INPUT onkeypress="return false;" onpaste="return false;" id="File1" type="file" name="File1" >

        Another way is to use 3 elements: + A textbox is set to read-only + A button + An input file element which is hidden on the web form. When the user clicks the button, you can open the Choose File dialog box, as soon as a file is selected you can assign the value of the input file to the read-only textbox.

        P 1 Reply Last reply
        0
        • M minhpc_bk

          Hi there, To disallow the user to type or paste a value to the textbox of the input file element, you simply create event handlers for the onkeypress and onpaste events and cancel the events:

          <INPUT onkeypress="return false;" onpaste="return false;" id="File1" type="file" name="File1" >

          Another way is to use 3 elements: + A textbox is set to read-only + A button + An input file element which is hidden on the web form. When the user clicks the button, you can open the Choose File dialog box, as soon as a file is selected you can assign the value of the input file to the read-only textbox.

          P Offline
          P Offline
          Program err
          wrote on last edited by
          #4

          Hi minhpc_bk ! Thnks for the code. It worked well.i added onkeydown="return false;" so as to avoid deleting the text in the text box of the control. But the pblm is that the cursor gets stuck once inside the text box of the control(due to onkeydown="return false;").Tab button doesn't help to go the next control! Can u suggest somethng for this so that user cant delete & simultaneously tab works as well ? :)

          M 1 Reply Last reply
          0
          • P Program err

            Hi minhpc_bk ! Thnks for the code. It worked well.i added onkeydown="return false;" so as to avoid deleting the text in the text box of the control. But the pblm is that the cursor gets stuck once inside the text box of the control(due to onkeydown="return false;").Tab button doesn't help to go the next control! Can u suggest somethng for this so that user cant delete & simultaneously tab works as well ? :)

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            In this case, you simply check the keycode of the Tab button, its keycode is 9:

            onkeydown="if(event.keyCode == 9) return true; return false;"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups