I have two checkboxes on a page:
<anthem:CheckBox ID="chk1" Text="Include Deactivated Users" runat="server" AutoCallBack="true" OnCheckedChanged="chk1_CheckedChanged" />
<anthem:CheckBox ID="chk2" Text="Exclude Deactivated Users" runat="server" AutoCallBack="true" OnCheckedChanged="chk2_CheckedChanged" />
Code behind for CheckedChanged events:
protected void chk1_CheckedChanged(object sender, EventArgs e)
{
//calls some random functions to check stuff
lstUsers.UpdateAfterCallBack = true; //updates a checkboxlist 'lstUsers'
chkAllUsers.UpdateAfterCallBack = true; //updates another checkbox
}
protected void chk2_CheckedChanged(object sender, EventArgs e)
{
CheckBox box = (CheckBox)sender;
if (box.Checked == true)
{
chk1.Checked = !box.Checked;
}
}
Here's the conditions I want:
chk1is checked.chk2is unchecked.chk2is then checked, which causeschk1to uncheck and fire it's event.chk2is checked.chk1is unchecked.chk1is then checked, which causeschk2to uncheck and fire it's event.
I'm only working on 1. right now, because if I get that working I can make the second work. The problem I'm having is, when chk2 is checked, it unchecks chk1 but chk1_CheckedChanged is never fired.
chk1_CheckedChanged does in work on it's own when checking/unchecking.
The weird thing is, if I check, uncheck, then check chk2, chk1_CheckedChanged gets fired but chk1 never changes, then chk2_CheckedChanged is fired.
I'm confused on what exactly is happening here.
I've messed around with AutoPostBack for the two checkboxes as that seemed to be a solution in similar problems but had no luck with that either.
Aucun commentaire:
Enregistrer un commentaire