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:
chk1
is checked.chk2
is unchecked.chk2
is then checked, which causeschk1
to uncheck and fire it's event.chk2
is checked.chk1
is unchecked.chk1
is then checked, which causeschk2
to 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