Web Pages: How To Set Focus on Textbox

Posted on 2011-10-13
Last Modified: 2012-05-12
Hi Experts!

This is ASP.NET 4.0 web pages (Razor) question; how do you set focus on the Username textbox?

<form method="post" action="">
<div class="formStyle01">
    <div class="row">
        <div class="label">
            <label for="username">
        <div class="input">
            <input type="text" id="username" name="username" value="@username" title="Username" @if (!usernameErrorMessage.IsEmpty())
                                                                                                {<text>class="input-validation-error"</text>} />
            @* Write any username validation errors to the page *@
            @if (!usernameErrorMessage.IsEmpty())
                <label for="username" class="field-validation-error">


When the page loads up we want the focus on the Username textbox.

Question by:allanau20
    LVL 25

    Accepted Solution

    Place this into the HEAD section of the page:

    <script type="text/javascript">
        window.onload = function() {

    Hope that helps.
    LVL 5

    Author Comment

    wow; u da best. ThankS!
    LVL 3

    Expert Comment

    <input type="text" tabindex="1" name="textfield" />

    it may help u

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now