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 check boxes on it. I am pulling data from a SQL DB and setting the initial on/off state of the check box based on the retrieved value. This works fine.
The problem starts when I try to check or un-check a checkbox. If it is checked it will un-check for a split second and then the check returns or vise versa (Un-checked to to checked state).
Here are the check boxes:
<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" />
The OnCheckedChange event for each one is basically them same (Only control ID name changes:
If [control ID].Checked = checked Then
[control ID].Checked = False
Else
[Control ID].checked = True
End IF
I also found an article here on SO that talked about using hidden text boxes and setting the checkbox based on the value from it. But I can't seem to get that to work. I think I am missing something there.
Here is that code:
If txbivpo.Text = "1" Then
ckbIVPO.Checked = True
Else
ckbIVPO.Checked = False
End If
If txbshtrm.Text = "1" Then
ckbShipTerms.Checked = True
Else
ckbShipTerms.Checked = False
End If
If txbqunotes.Text = "1" Then
ckbQuNotes.Checked = True
Else
ckbQuNotes.Checked = False
End If
If txbmatsurfin.Text = "1" Then
ckbMatSurFin.Checked = True
Else
ckbMatSurFin.Checked = False
End If
If txbfabfasext.Text = "1" Then
ckbFabFasExt.Checked = True
Else
ckbFabFasExt.Checked = False
End If
I just can't seem to get this to work. I am sure that I am missing something but I am not sure what it is. I am also not set in stone as to doing it this way. I am using VB because I am not very good with C#. (Actually I flat out suck at C#!) I am using the hidden text boxes to pull the data for the update query if the user changes something and I need to update the SQL.
Can anyone help me or point me to a clear example of how to simply have the check box change state, and stay, and then be able to update the hidden text box so the query will update correctly?
Aucun commentaire:
Enregistrer un commentaire