Need to change Browse button text

  • Thread starter Christopher Attard
  • Start date
C

Christopher Attard

Hello,
I'm using an <input type=file> control in an asp.net page and I need to change the text of the "Browse..." button cos the page needs to be multi-lingual.

Any ideas or suggestions?

Thanks,
Chris
 
A

Alessandro Zifiglio

hi Chris,
You cannot reflect the style properties set on the INPUT element or change
the text on the Browse button, but there is a way to get most of the
functionality you need. First, you'll need to actually use a file upload
element for both its browsing and uploading abilities. Next you'll have to
add your own button and text field to the page. Then, to tie them together,
you'll have the button's onClick event trigger the click method of the file
upload element and the onChange event of the file upload element set the
value of the text field. Then, you can customize the appearance of the
button and text field as usual. Here's a sample:


<INPUT TYPE="file" ID="filUpload" STYLE="display:none"
onChange="txtFilename.value = this.value;">
<asp:input runat="server" ID="txtFilename"
STYLE="FONT-FAMILY:Tahoma;FONT-SIZE:9pt"
SIZE="25" DISABLED>
<INPUT TYPE="button" ID="btnBrowse" STYLE="FONT-FAMILY:Tahoma;FONT-SIZE:9pt;
BACKGROUND-COLOR:peachpuff" onClick="filUpload.click()"
VALUE="Choose a File">


However theres a catch. Because of the file upload element's security
restrictions, this workaround does not allow the user to change the location
of the file to be uploaded simply by editing the value of the text field
which is why its DISABLED attribute is set.


Christopher Attard said:
Hello,
I'm using an <input type=file> control in an asp.net page and I
need to change the text of the "Browse..." button cos the page needs to be
multi-lingual.
 
A

Alessandro Zifiglio

your welcome chris. I had actually forgotten to clean up and left an un
wanted <asp:input tag in there with runat="server" when i wanted to display
a normal html input element for the sample, but you got it working still,
great ;)

for everybody else viewing this post here is a cleanup :

<input type="file" id="filupload" style="display:none"
onchange="txtfilename.value = this.value;" />
<input type="text" id="txtfilename" style="font-family:tahoma;font-size:9pt"
size="25" disabled="false" />
<input type="button" id="btnbrowse" style="font-family:tahoma;font-size:9pt;
background-color:peachpuff" onclick="filupload.click()"
value="choose a file" />
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,093
Messages
2,570,609
Members
47,229
Latest member
bennettnguyen

Latest Threads

Top