.NET Tip of The Day
Learn one new .NET trick every day
Быстрое пополнение счета телефона      Login or Join

How to set the default focus to a control when the page loads

This is another extremely simple thing that can be done without resorting to writing JavaScript. If you only have a single textbox (or two) on a page why should the user have to click in the textbox to start typing? Shouldn't the cursor already be blinking in the textbox so they can type away? Using the DefaultFocus property of the HtmlForm control you can easily do this.

    <form id="frm" DefaultFocus="txtUserName" runat="server">

       ...

    </form>



7/25/2007

Comments:

Ok, nice but how do you do this if you are using a masterpage?

Bjorn van der Neut 2/26/2008 2:09:25 PM

Read this tip - http://dotnettipoftheday.org/tips/locate_nested_control.aspx

Enable ASP.NET tracing to see controls tree and how they are nested inside each other.

kostya.ly 3/9/2008 1:03:20 AM

this default button prperty can set to asp:panel control also so in master page use panel..:)

srikanth 6/2/2008 11:54:38 AM

Name
URL
E-mail
Provide your e-mail address to receive notification about new comments.
Message
HTML tags are not supported.
Please add 2 and 4 and type the answer here:
RSS .NET Tip of The Day
Subscribe to receive one tip from the .NET Tips and Tricks Community per day.
Previous Tips of The Day
The best of the .NET Tips & Tricks Community.
.NET Practitioners .NET Tips & Tricks Community
Every .NET practitioner has a trick up in their sleeve. This is the place to share it with other .NET people.
Submit a Tip
Discovered a new trick? Share it with others.
My Tips
Manage tips you authored.