Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4382414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:46:35+00:00 2026-05-21T12:46:35+00:00

Greetings, I’ve been scanning the internet on how to do this, but so far

  • 0

Greetings,

I’ve been scanning the internet on how to do this, but so far no luck. There are numerous solutions posted, especially on this website (thank you for that), but none seem to work for me. This will most probably be because I am only learning asp.net since 4 months now, and lack the necessary knowledge.

What I would like to do is set focus on the username input textbox when the page is loaded. I’ve seen many solutions, such as “defaultfocus”, body onload, etc, etc. Anyone can give me a simple way to accomplish this?

Our project is a MVC 2 Web application. We have a master site, which collects all the contentplaceholders. Here is the link to the logon.aspx

<div id="Clogin" onclick="logout();">
    <asp:ContentPlaceHolder ID="LoginContent" runat="server" />            
</div>

The LogOn.aspx is practically the same as the auto-generated one. And here is the textbox I would like to set focus on:

<div class="login-field">
    <%: Html.TextBoxFor(m => m.UserName)%>
    <%: Html.ValidationMessageFor(m => m.UserName) %>
</div>

How can I trigger the onload event, be it in the master page, or the LogOn page, so that the focus is generated on that particular textbox?

Thanks in advance, and apologies for having to rely on your knowledge.

Sincerely,

Nicolas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:46:35+00:00Added an answer on May 21, 2026 at 12:46 pm

    You will need to use javascript for this. If you are using jquery you could include the following script:

    $(function() {
        $('#UserName').focus();
    });
    

    Another possibility is to do this in the body tag:

    <body onload="document.getElementById('UserName').focus();">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I've read some threads about this topic, but actually I was unable to
Greetings I may have imagined this but does anyone know if Last.fm previously used
Greetings, I've been with this about 1 or 2 hours and it seems I
Greetings to all of you ! This is the second time I encounter quite
Greetings all, Is there a built in way to know when a user is
Greetings I've been working on a homework in which I must create a linked
Greetings all, Is there any issue in the following logic for allocating 2D array:
Greetings! I am working on an AS2 website with MovieClips for pages that swap
Greetings, everyone! Examining my own code, I came up to this interesting line: const
Greetings , I am a new developer in BlackBerry Application. I have been working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.