How to change the Text of the browse button in the FileUpload Control (System.Web.UI.WebControls) How to change the Text of the browse button in the FileUpload Control (System.Web.UI.WebControls) asp.net asp.net

How to change the Text of the browse button in the FileUpload Control (System.Web.UI.WebControls)


This is old, but wanted to offer another solution. You can use jQuery on a standard HTML hyperlink and fire asp:FileUpload on click of the HREF. Just hide the asp:FileUpload at design and doctor the href any way you'd like.

Link

<a href="#" id="lnkAttachSOW">Attach File</a>

asp:FileUpload

<asp:FileUpload ID="fuSOW" runat="server" style="visibility:hidden;"/>

Then the jQuery:

$("#lnkAttachSOW").click(function () {    $("#fuSOW").click();});


This isn't technically possible for security purposes, so the user cannot be misled.

However, there are a couple of workarounds, although these require working with the raw HTML rather than the .NET server control - take a look at http://www.quirksmode.org/dom/inputfile.html for one example.


This was how I did it in .NET using AsynchFileUpload and JavaScript...

<asp:Button ID="bUploadPicture" runat="server" Text="Upload Picture"    OnClientClick="document.getElementById('<%=tFileUpload1.ClientID%>')        .click();return (false);" /><div style="display:none;visibility:hidden;">     <asp:AsyncFileUpload ID="tFileUpload1" runat="server"         OnUploadedComplete="tFileUpload1_UploadedComplete" /></div>