Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change browse button caption from type "file"

Status
Not open for further replies.

bclt

Programmer
Mar 13, 2005
363
0
0
GR
Hi,

As i add a form: file upload, the button of it has "Browser" caption. Is there any way to change its caption? (Trying to localize).

If not possible can i somehow display the folder browser dialog (that is on wondows applications)? If yes i'm able to drag a button, change its text and on click display this dialog.


Tnx .
 
AFAIK there is no way to change the text of the button on a file input control...

However you could have one hidden using CSS and then "click" it using javascript when another button is clicked, which would have the same effect of opening the dialog without the user ever seeing the control.

Of course you would have to handle the diplay to the user of your custom interface so it makes sense to them. If this was something you wished to reuse it could be fairly easily wrapped up as a server control with all the functionality self-contained.

Code maybe something like this, not tested but a starting point...
Code:
<input type="file" id="fileInput" runat="server" style="visibilty:hidden" />
<input type="button" id="openDialogButton" onclick="document.getElementById('fileInput').click();" value="open file dialog" />
The above should work in IE but may need tweaking for Mozilla, maybe not cause it is DOM?

I guess the bottom line is, is it worht the extra effort to change somethign which is built in?

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
crazyboybert:
I don't believe you can programmatically click the "input type=file" control's button like this. This being by design, for security reasons.
I could be confusing this with something else, but I recall attempting to just that, and not being able to.
 
So,

Is there any way, as i click a .net component button; to show the "folderbrowser" dialog?

Tnx .
 
Yes there is. Here is a way I've used in the past (when just using html pages) that you can adapt to use a button server control (this example just uses a html button).
Code:
<input type=file name=browse style="display: none;">
<input type=text name=file>
<input type=button style="font-style:veranda; font-size:12px; font-weight:bold;text-transform:lowercase;color:white;background-color:#A2C382;height:22px;border-style:ridge;text-align:center;" onClick="browse.click();file.value=browse.value;browse.disabled=true" value="Select a File...">

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Ok sounds good, that is essentially the same as the method I proposed with a textbox as a gui for the browsed file and some non-DOM Javascript ;-) If ca8msm has used this before it sounds like the type="file" input can be clicked programtically LFCfan.

Like i said though I havent tried it and have no what browsers will support. May well be the case that IE only will allow or perhaps IE only assuming the user doesnt have XP SP2 installed ... I just don't know.

Either way if your succesful or not I'd be interested to hear the results.

Good luck.

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Yes (apologies Rob) this was essentially what you had suggested - I just dug out an example that I had used in the past [smile]

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top