How can I send a click event to a HTML filefield control

Posted on 2006-04-11
Last Modified: 2008-02-01
I have an ASPX from that is used for maintaining data in a SQL table of job requests.
Some of the requests will have files attached.
Currently, I am using a 2nd page to find and attach files.
This page has a HTML filefield control and an asp  button with code behind to insert the selected file into the database.

I would like to reduce mouse clicks by having the form load event send a click event to the filefield control so that the file browser control is displayed without the need to click the filefield control's button.
Question by:JimMorganAgview
    LVL 18

    Expert Comment

    Hi JimMorganAgview,
    Use javascript to do such stuff. or for more detail ask the question in ASP.NET section of EE

    LVL 11

    Expert Comment

    Here it is quick and dirty..

    <INPUT type="file" id=file1 name=file1>

    Author Comment

    I have tried the script suggested by coopzz and get a runtime error
    "Microsoft JScript runtime error: file1 is undefined".
    This occurs, even after I change to <INPUT type="file" id="file1" name="file1">.
    LVL 11

    Accepted Solution

    it's most probably just the browser version your in... howevery you normally link up your buttons in your code is what you need to do.

    but what your after is the .click(); on the button object. once you have the reference it works fine..

    fyi: it works fine just that code in a html file in IE 6 sp 2

    one of the ways i use is a generic getObj function like so.

    <INPUT type="file" id=file1 name=file1>
    function gObj( id )
    {      var o;
          {      o = document.all(id);
          }catch( ex )
          {      o = document.getElementById[id];
          }return o;
    gObj('file1').click(); //call the open file.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Linq Unique list ? 3 29
    How to parse date from file path? 4 31
    Starting to learn JAVA, 7 34
    VB.Net - Find String in Array 3 17
    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now