change text from fileupload Asp.net

Asked

Viewed 568 times

0

You can change the text inside Fileupload?

I wanted to change the text "No files selected"

inserir a descrição da imagem aqui

1 answer

1


There is no way to change the text within the input, each browser renders the element in its own way, but there is a way to use some workaround to resolve. An alternative is to add a label of its own that overlaps with the original, allowing you to use any text you want:

function fileChange() {
  var e = document.getElementById('file');
  if(e.value == "")
  {
      fileLabel.innerHTML = "Nenhum arquivo selecionado";
  }
  else
  {
      var theSplit = e.value.split('\\');
      fileLabel.innerHTML = theSplit[theSplit.length-1];
  }

}

fileChange();
input[type=file]{
    color:transparent;
}

#fileLabel {
  margin-left: -160px
}
<div>
  <input type='file' title="Selecione um arquivo" id="file" onchange="fileChange()" >
   <label id="fileLabel">Nenhum arquivo selecionado</label>
 </div>

  • could you start Vb? is because there is an error in theSplit

  • but that part is Javascript cannot be executed in VB :) this part must be on the page (vbhtml, html, aspx, ascx, etc) or in a file .js

  • div places itself under Fileupload?

  • 1

    actually Fileupload is inside the div, but you can do it without this div as well

  • worked , only copied and now there are two upload items equal

  • I don’t understand, the code won’t duplicate the input, it has to have only one in the div.. doubled the input or only the label showing the message?

  • doubled the square where you put things. There were two, but I did what you told me of ( " input[type=file]{ color:Transparent; } ) and solved my problem

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.