Display TextBox when CheckBox is checked in ASP.Net using C#

Category > ASP.NET || Published on : Friday, January 11, 2019 || Views: 6242 || Display TextBox when CheckBox is checked


Introduction

Here Pawan Kumar will explain how to Display TextBox when CheckBox is checked in ASP.Net using C#

Description

Now I will explain How to Display TextBox when CheckBox is checked in ASP.Net using C#

So follow the steps to learn Display TextBox when CheckBox is checked in ASP.Net using C#

CS.aspx

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>asp.net sourec code - Display TextBox when CheckBox is checked in ASP.Net using C# </title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:CheckBox ID="chkAadhaar" Text="Do you have kAadhaar?" runat="server" OnCheckedChanged="OnCheckChanged"
        AutoPostBack="true" />
    <hr />
    <asp:Panel ID="pnlAadhaar" runat="server" Visible="false">
        Aadhaar Number:
        <asp:TextBox ID = "txtAadhaar Number" runat="server" />
    </asp:Panel>
    </form>
</body>
</html>

CS.aspx.cs

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

public partial class CS : System.Web.UI.Page
{
    protected void OnCheckChanged(object sender, EventArgs e)
    {
        pnlAadhaar.Visible = chkAadhaar.Checked;
    }
}

 

Conclusion:

So, In this tutorial we have learned, Display TextBox when CheckBox is checked in ASP.Net using C#