How to change Text in FileUpload control

Last post 11-16-2009 3:57 AM by sethia4u. 23 replies.

Sort Posts:

  • How to change Text in FileUpload control

    06-13-2007, 11:07 PM
    • Member
      12 point Member
    • barrysuku
    • Member since 05-23-2007, 12:02 AM
    • Posts 72

    Can we change text of Browse Button in FileUpload Control to Other language? Am working on Localization. Am not able to change name cause When i generate Local Resource file for FileUPload component only this comes (FileUpload1Resource1.ToolTip). I want to change Button Text. How can i change?

  • Re: How to change Text in FileUpload control

    06-14-2007, 7:38 AM
    Answer
    • Contributor
      5,590 point Contributor
    • deblendewim
    • Member since 12-20-2006, 4:32 PM
    • Antwerp, Belgium
    • Posts 951

    I'm not sure you can change it.

    I did it this way:

    1. make a button (for instance an input; it doesn't even have to run at server)
    2. when the button is clicked, perform some javascript
    3. the javascript will get the fileInput, and perform the click on it.
    4. the 'Open File'-dialog is opened by pressing on a button you can modify any way you want.
    5. Hide the fileInput control

    Hope this helps!
    Wim

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: How to change Text in FileUpload control

    06-14-2007, 10:14 AM
    • Member
      19 point Member
    • mp_mdavies
    • Member since 06-08-2007, 8:44 AM
    • Posts 12

    Hi there, two questions:

    1) Have you set the Language UI thread of the site?

    2) Have you set tried setting your OS to a different language?

     I ask becuase if your using the asp.net control then I beleive it will use the default settings for the language of the control, but I'm not sure if it takes the language from the thread or the OS so worth setting Windows to another Language to see what language the button appears as.

     

    Michael
     

  • Re: How to change Text in FileUpload control

    06-19-2007, 5:14 AM
    Answer

    Hi,

    As far as I know, we cannot localize the file upload dialog box. It is a client call and its language depends on the language of the OS on the client side.

    If you just wish to change the language on the click button, you can use deblendewim's suggestion, to make a file upload control yourself. The only way to change the file open dialog box is to construct an ActiveX control of your own to do this.

    If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!

    Sincerely,
    Kevin Yu
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Mark as Not Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: How to change Text in FileUpload control

    08-01-2007, 2:15 PM
    • Member
      9 point Member
    • rdelgadoj
    • Member since 08-01-2007, 6:12 PM
    • Costa Rica
    • Posts 5

    Hi,

    I'm trying to do what you said... but my javascript is not working Could you show me you javascript (step 3) pls?

     

    Thanks in advance

  • Re: How to change Text in FileUpload control

    08-02-2007, 3:40 AM
    • Contributor
      5,590 point Contributor
    • deblendewim
    • Member since 12-20-2006, 4:32 PM
    • Antwerp, Belgium
    • Posts 951

    Hi rdelgadoj,

    Here is a complete example. Both buttons trigger the hidden input (type="file") element. One button is a html button (pure clientside), the other button is the asp:button.

     

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript">
    	  function triggerFileUpload()
    	  {
    		document.getElementById("File1").click();
    	  }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    	  <input id="File1" type="file" style=" visibility:hidden;" />
    	  <br />
    	  <br />
    	  <asp:Button ID="Button1" OnClientClick="triggerFileUpload()" runat="server" Text="ASPNET Button" />
    	  <br />
    	  <br />
    	  <input id="Button2" type="button" onclick="triggerFileUpload()" value="HTML Button" />
    	  <br />
    	  <br />
        </div>
        </form>
    </body>
    </html>

     If you have any other questions/remarks, please let me know.

    Good luck!
    Wim

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: How to change Text in FileUpload control

    08-03-2007, 10:57 AM
    • Member
      9 point Member
    • rdelgadoj
    • Member since 08-01-2007, 6:12 PM
    • Costa Rica
    • Posts 5

    Hi Wim,

    Thanks very much.

    This is working fine!, but,  I realize that if I put "runat="server"" to the File1 object, the "File Browser" window is not raised. I need to get the posted file in the "CodeBehind"... How do I do this?

     

    Thanks!

  • Re: How to change Text in FileUpload control

    08-09-2007, 5:30 AM
    Answer
    • Contributor
      5,590 point Contributor
    • deblendewim
    • Member since 12-20-2006, 4:32 PM
    • Antwerp, Belgium
    • Posts 951

    Hi rdelgadoj,

    Sorry for my late reply ....

    I think that the value of the input control (type=file) is not remembered during postback.
    One thing is weird: If I put runat="server" on my File1 control, it still gets triggered and the Open File Dialog still pop's up? (But, it doesn't have to be runat="server" since the value isn't remembered during postback)

     

    You can solve this by doing the following ....

    1. in the input control (type=file) you have an event onchange.
    2. This event gets triggered whenever the value of the control changes
    3. When that occurs, call a javascript function to get the value of the input-control (type=file)
    4. Store that value in an input-control (type=hidden)
    5. make sure the input control (type=hidden) is runat="server".
    6. then in code-behind, get the value out of the hidden input control. (This value is remembered during postback!)

    Here is an example:

    html:

     

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript">
    	  function triggerFileUpload()
    	  {
    		document.getElementById("File1").click();
    	  }
    	  
    	  function setHiddenValue()
    	  {
    		document.getElementById("Hidden1").value = document.getElementById("File1").value;
    	  }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    	  <input runat="server" id="Hidden1" type="hidden" />
    	  <input runat="server" id="File1" type="file" onchange="setHiddenValue()" style=" visibility:hidden;" />
    	  <br />
    	  <br />
    	  <asp:Button ID="Button1" OnClientClick="triggerFileUpload()" runat="server" Text="ASPNET Button" />
    	  <br />
    	  <br />
    	  <input id="Button2" type="button" onclick="triggerFileUpload()" value="HTML Button" />
    	  <br />
    	  <br />
    	  <asp:Button ID="Button3" runat="server" Text="Go CodeBehind To Get Input Value" />
        </div>
        </form>
    </body>
    </html>

     code-behind:

    Partial Class _Default
        Inherits System.Web.UI.Page
    
      Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
    	Dim inputValue As String
    	inputValue = Me.Hidden1.Value
    
      End Sub
    End Class

     Hope this helps!
    Wim

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: How to change Text in FileUpload control

    08-09-2007, 12:40 PM
    • Member
      9 point Member
    • rdelgadoj
    • Member since 08-01-2007, 6:12 PM
    • Costa Rica
    • Posts 5

    Win,

    Thanks a lot! This solved my problem.

     I have to fix some issues because I'm working with master page, so, I have ContentPlaceHolder that changes the client's name controls and also I'm using an UpdatePanel (UpdatePanels do not supports FileUploads)....

     

    This is great!

     Again Thanks a lot!

  • Re: How to change Text in FileUpload control

    09-19-2007, 5:23 AM

    Sadi want your help plzzzzzzzzzzzzzzz.

    this code is run in html page and I'm using aspx page with masterpage so can you help me to get the same code that can work in my project plz.

    thx

    Filed under:
  • Re: How to change Text in FileUpload control

    09-19-2007, 8:35 AM
    • Contributor
      5,590 point Contributor
    • deblendewim
    • Member since 12-20-2006, 4:32 PM
    • Antwerp, Belgium
    • Posts 951

    Hi ahmed,

    The code given is actually an aspx page. Only the content inside the <html></html> is given.

     

    Can you be a bit more specific about what you want to achieve? Do you want your customized fileupload on the master, child?
    How do you want to customize it etc.

    Did you try to add the above code to your application?
    Do you get errors, what goes wrong?

     

    Kind regards,
    Wim

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: How to change Text in FileUpload control

    09-20-2007, 7:51 AM

    thx Wim for replaying me.

    look Wim that is the code I write it and it doesn't work see it and replay me ok thx .

     

     

    <%@ Page Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="final.aspx.cs" Inherits="test_Default" Title="Untitled Page" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <script language="JavaScript">

    <!--

     

    function fireFileClick()

    {

    var objfile = document.getElementById('File1');

    objfile.click();

    var objTextBox = document.getElementById('Text1');

    objTextBox.value = objfile.value;

    }

    function setHiddenValue()

    {

    document.getElementById(
    "Hidden1").value = document.getElementById("File1").value;

    }

    // -->

    </script>

    <input id="Hidden1" type="hidden" />

    <input runat="server" onchange="setHiddenValue()" id="File1" type="file" style=" visibility:hidden;" />

    <br />

    <br />

    <asp:Button ID="Button1" OnClientClick="fireFileClick()" runat="server" Text="ASPNET Button" />

    <input id="Text1" type="text" />

    <br />

    <br />

    <input id="Button2" type="button" onclick="fireFileClick()" value="HTML Button" />

    <br />

    <br />

     

    </asp:Content>

  • Re: How to change Text in FileUpload control

    09-20-2007, 7:51 AM

    thx Wim for replaying me.

    look Wim that is the code I write it and it doesn't work see it and replay me ok thx .

     

     

    <%@ Page Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="final.aspx.cs" Inherits="test_Default" Title="Untitled Page" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <script language="JavaScript">

    <!--

     

    function fireFileClick()

    {

    var objfile = document.getElementById('File1');

    objfile.click();

    var objTextBox = document.getElementById('Text1');

    objTextBox.value = objfile.value;

    }

    function setHiddenValue()

    {

    document.getElementById(
    "Hidden1").value = document.getElementById("File1").value;

    }

    // -->

    </script>

    <input id="Hidden1" type="hidden" />

    <input runat="server" onchange="setHiddenValue()" id="File1" type="file" style=" visibility:hidden;" />

    <br />

    <br />

    <asp:Button ID="Button1" OnClientClick="fireFileClick()" runat="server" Text="ASPNET Button" />

    <input id="Text1" type="text" />

    <br />

    <br />

    <input id="Button2" type="button" onclick="fireFileClick()" value="HTML Button" />

    <br />

    <br />

     

    </asp:Content>

  • Re: How to change Text in FileUpload control

    09-20-2007, 8:01 AM

    sorry for repeating it is my mistake sorry but i want to use upload file as standard not input becouse this control in about 40 page and i can't change the code from start again so try to help me Smile

  • Re: How to change Text in FileUpload control

    09-20-2007, 8:36 AM
    • Member
      9 point Member
    • rdelgadoj
    • Member since 08-01-2007, 6:12 PM
    • Costa Rica
    • Posts 5

    Just for notice! 

    The code posted by Win should work... the really issue here is What will we do with the file (file path or file name)?

    Post a file in a server is a little bit complicated, going on a step forward (after we get the file name in some way)... How do we post the file to the server? The HTTPPostedFile class has its "FileName" property as "Read Only", also the "FileName" property of the UploadFile control... I spent a little time trying and finally I had to use the UploadFile as it. I improve a little the interface using this version of an UploadFile http://en.fileuploadajax.subgurim.net/ works fine, and so far it results stable.

     I hope help somebody

Page 1 of 2 (24 items) 1 2 Next >