In this article I will explain with an example, how to display TextBox when CheckBox is checked in ASP.Net using C# and VB.Net.
The CheckBox will be assigned OnCheckChanged event handler and when the CheckBox is checked (selected), the TextBox will be displayed and when the CheckBox is unchecked (unselected) the TextBox will be hidden in ASP.Net using C# and VB.Net.
 
 
HTML Markup
The following HTML Markup consists of a CheckBox and a Panel containing a TextBox. The CheckBox has been assigned OnCheckChanged event handler and AutoPostBack property is set to true.
<asp:CheckBox ID="chkPassport" Text="Do you have Passport?" runat="server" OnCheckedChanged="OnCheckChanged"
    AutoPostBack="true" />
<hr />
<asp:Panel ID="pnlPassport" runat="server" Visible="false">
    Passport Number:
    <asp:TextBox ID = "txtPassport" runat="server" />
</asp:Panel>
 
 
Displaying TextBox when CheckBox is checked in ASP.Net using C# and VB.Net
Inside the OnCheckChanged event handler, the Panel containing the TextBox is displayed when the CheckBox is checked (selected) and it is hidden when the CheckBox is unchecked (unselected).
C#
protected void OnCheckChanged(object sender, EventArgs e)
{
    pnlPassport.Visible = chkPassport.Checked;
}
 
VB.Net
Protected Sub OnCheckChanged(ByVal sender As Object, ByVal e As EventArgs)
    pnlPassport.Visible = chkPassport.Checked
End Sub
 
 
Screenshot
Display TextBox when CheckBox is checked in ASP.Net using C# and VB.Net
 
 
Demo
 
 
Downloads