user3227070 user3227070 - 1 year ago 85
C# Question display textbox on item checked

So just starting out with I want to display my textbox when my checkbox is checked, but this doesn't seem to be working. I also tried with the visible property, but that didn't work either. What am I doing wrong exactly?


protected void checked_CheckedChanged(object sender, EventArgs e)
text.Style["display"] = "block";


<!DOCTYPE html>

<html xmlns="">
<head runat="server">
<form id="form1" runat="server">
<p>gehuwd/samenwonend<asp:checkbox runat="server" ID="checked" OnCheckedChanged="checked_CheckedChanged"></asp:checkbox>
<asp:TextBox runat="server" ID="text" style="display:none"></asp:TextBox>

Answer Source

Use the AutoPostBack property for checkbox and set it to true:

<asp:checkbox runat="server" ID="checked" OnCheckedChanged="checked_CheckedChanged" AutoPostBack="true"></asp:checkbox>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download