Mega Code Archive

 
Categories / ASP.Net Tutorial / Page Lifecycle
 

Use the input focus capability of ASP NET 2 0 and superior

<%@ Page language="C#" %> <script runat="server">    void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)            this.SetFocus("Pswd");    } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title>Focus to the control</title> </head> <body>     <div id="pageContent">         <form id="Form1" runat="server">             <h1>Please, login</h1>             <h3>User</h3>             <asp:textbox runat="server" id="UserName" text="" /><br />             <h3>Password</h3>             <asp:textbox runat="server" id="Pswd" text="" TextMode="Password" /><br />             <asp:button runat="server" id="Login" text="Log in" />             <hr />         </form>     </div> </body> </html>