I have looked many different solutions but almost all of them are not what I am trying to do.
I have an aspx page that has 5 checkboxes on it. I am pulling data from an SQL DB and setting the initial on/off state of the checkbox based on the retrieved value. This works fine.
The problem starts when I try to check or uncheck a checkbox. If it is checked it will uncheck for a split second and then the check returns or vice versa (unchecked to checked state).
Here are the checkboxes:
<asp:CheckBox ID="ckbIVPO" runat="server" Text=" Invoice Value & P.O.#" OnCheckedChanged="ckbIVPO_CheckedChanged" AutoPostBack="true" />
<asp:CheckBox ID="ckbQuNotes" runat="server" Text=" Quality Notes" OnCheckedChanged="ckbQuNotes_CheckedChanged" AutoPostBack="true" />
<asp:CheckBox ID="ckbShipTerms" runat="server" Text=" Ship To & Shipping Terms" OnCheckedChanged="ckbShipTerms_CheckedChanged" AutoPostBack="true" />
<asp:CheckBox ID="ckbMatSurFin" runat="server" Text=" Material/Surface/Finish" OnCheckedChanged="ckbMatSurFin_CheckedChanged" AutoPostBack="true" />
<asp:CheckBox ID="ckbFabFasExt" runat="server" Text=" Fabrication & Fastner Extras" OnCheckedChanged="ckbFabFasExt_CheckedChanged" AutoPostBack="true" />
If [control ID].Checked = checked Then
[control ID].Checked = False
[Control ID].checked = True
If txbivpo.Text = "1" Then
ckbIVPO.Checked = True
ckbIVPO.Checked = False
If txbshtrm.Text = "1" Then
ckbShipTerms.Checked = True
ckbShipTerms.Checked = False
If txbqunotes.Text = "1" Then
ckbQuNotes.Checked = True
ckbQuNotes.Checked = False
If txbmatsurfin.Text = "1" Then
ckbMatSurFin.Checked = True
ckbMatSurFin.Checked = False
If txbfabfasext.Text = "1" Then
ckbFabFasExt.Checked = True
ckbFabFasExt.Checked = False
This is a guess since the code for setting the correct textbox from the DB is not shown. But I think you have to wrap that piece of code in a IsPostBack check:
If Not IsPostBack Then setCheckBoxValuesFromDB End If
What probably happens is when a checkbox is clicked a PostBack is performed. In that PostBack , presumably in Page_load, the default values are retrieved from the database and will overwrite the ones the user clicked.