Goal: User toggles a checkbox, and then a modal pops up to confirm either Yes(update DB), or No (undo selection). I want to have checkbox reverse user selection IF they click the No button in the confirmation dialog. For example: If they click to toggle On, but when the confirmation comes they click No, it should toggle back to Off
Problem/What's happening: When I debug, it says the value is being reversed, however on the page I can see nothing has visually happened
What I've tried: I tried with conditional, setting the checkboxvariable.Checked = true or false accordingly. But it doesn't change anything on screen. Ive used the debugger to watch values while doing this I've tried setting it simply with no conditions, and also tried it with different conditions. How to reset a checkbox value
C#:
//Checkbox event
protected void cbUpdateAvailability_Click(object sender, EventArgs e)
{
CheckBox cbSender = (CheckBox)sender;
providerIndex = getProviderIndexCB(cbSender.ClientID);//int providerIndex = getProviderIndexCB(cbSender.ClientID);
Session["providerIndex"] = providerIndex;
availableTxt.Text = (cbSender.Checked) ? "available" : "unavailable";
DrName.Text = providerStatsListDto.ProviderStatsList[providerIndex].LastName;
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "availabilityModal", "$('#availabilityModal').modal();", true);
upModal.Update();
}
//Confirmation Button click event
protected void btnUpdateAvailability_Click(object sender, EventArgs e)
{
Button btnSender = (Button)sender;
if (btnSender.Text == "Yes") {
//Update DB
}
else
{
//If they click No , flip checkbox back
//Session variable to know which checkbox?
chkOnOff2.Checked = (chkOnOff2.Checked) ? false : true; //even when Checked becomes false, it doesn't visually change, why?
//chkOnOff2.Checked = (availableTxt.Text == "available") ? false : true;
}
Aucun commentaire:
Enregistrer un commentaire