0





66

Advertisement

So just starting out with asp.net... 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?

Code:

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

Layout:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <p>gehuwd/samenwonend<asp:checkbox runat="server" ID="checked" OnCheckedChanged="checked_CheckedChanged"></asp:checkbox>
        </p>
        <asp:TextBox runat="server" ID="text" style="display:none"></asp:TextBox>
    </form>
</body>
</html>
Question author User3117628 | Source

Advertisement


0


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

<asp:checkbox runat="server" ID="checked" OnCheckedChanged="checked_CheckedChanged" AutoPostBack="true"></asp:checkbox>
Answer author At-2016