Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

104
Visualizações
jquery how to set input focus on control

Hey I am very new to jquery using asp.net, and I was wondering how to set focus on a textbox using jquery.

I have my script in my HeaderContent but it is not working, no focus on load. And yes I know this can be done on the server side as well, but I am just trying to get better and more familiar with jquery. Thanks.

<script type="text/javascript">
   $(document).ready(function () {
      $("#MainContent_LoginUser_UserName").focus();
   });
</script>
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Your code is correct. If it is failing, chances are $("#MainContent_LoginUser_UserName") is not the correct selector value or perhaps jQuery is not correctly loaded.

If you are using jQuery alongside standard ASP.NET JavaScript, then the '$' will not be mapped to jQuery, but instead to ASP.NET's JavaScript framework. You may need to substitute $("#foo") for jQuery("#foo").

over 4 years ago · Santiago Trujillo Relatório

0

if your MainContent_LoginUser_UserName text box is a server side control, it will not work, because the id of the control will be different, thanks to the unique id asp.net associated with your server site controllers.

Try to change to this line:

$("[id$=MainContent_LoginUser_UserName]").focus();

and check if it works!

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda