mardi 17 mars 2015

Unable to uncheck checkbox with postback

I've got several checkboxes which are used to hide and unhide asp.net panels, I've done this using C# which is why I needed the postback.


Now initially the panels are hidden and my code works fine when checked, but when I try to uncheck them they retain their values after postback and the panels are still visible.


Here's my code:


Markup:



<asp:CheckBox ID="cbxHideShow" runat="server" AutoPostBack="true" OnCheckedChanged="cbxHideShow_CheckedChanged" Text="Hide/Show Panel"/>


and code-behind:



protected void cbxHideShow_CheckedChanged(object sender, EventArgs e)
{
if (cbxHideShow.Checked = true)
{
Panel1.Visible = true;
}
else
{
Panel1.Visible = false;
}
}


If someone could let me know what I'm doing wrong I would very much appreciate it.





Aucun commentaire:

Enregistrer un commentaire