How to set focus on an ASP.Net TextBox Control when the page loads

Two things:
1. Give your BODY Tag and ID and include ‘Runat=Server’
(like – - <body id=”bdyMain” Runat=”Server”>)
2. In the Page_Load event:

if not Page.IsPostBack then bdyMain.attributes("onload")="document.form1.TextBox1.focus();" end if

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>