How to set focus on control in C#

Category > ASP.NET || Published on : Wednesday, April 7, 2021 || Views: 64 || set focus on control in C#


Introduction

Here Pawan Kumar will explain how to set focus on control in C#

Description

In previous post I have explained Assign datepicker to runtime/dynamic textboxes in ASP.NET using jQuery, Show Asp.Net Gridview Row Details using Bootstrap Tooltip on MouseHover GridView Row Cell, Best 7 Resources for 3 tier architecture Asp.Net, Show Hide Password Using Javascript ASP.NET, How to Create Tab Control Using jQuery In Asp.Net, jQuery Datepicker Calendar With Slide Down Effect In Asp.Net, and many more articles.

Now I will explain How set focus on control in C#

ASPX HTML Code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        </div>
    </form>
</body>
</html>

Code Behind Codes:-

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

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

Conclusion:

So, In this tutorial we have learned, how to set focus on control in C# In Asp.Net

Download Source Codes