Set Focus on Text Box at Page Load

Sandeepraturi
Posted by Sandeepraturi under ASP.NET category on | Points: 40 | Views : 940
*************************************************Html Code***********************************
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Set Focus on TextBox</title>
</head>
<body>
<form id="form1" runat="server">
<div align="center" style="width:300px">
<table>
<tr><td>Name:</td><td><asp:TextBox ID="TextBox1" runat="server" TabIndex="0"></asp:TextBox></td></tr>
<tr><td>FName:</td><td><asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox></td></tr>
<tr><td>MName:</td><td><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td></tr>
<tr><td>Address:</td><td><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td></tr>
</table>
<br />
</div>
</form>
</body>
</html>

***************************************************C# Code******************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class set_focus : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Focus();
}
}

Comments or Responses

Login to post response