0

I am trying to access 3 checkboxes on a page that were created dynamically from database info on PageLoad. I can see these checkboxes in the web Page Source with ID's equal to T1, T2 and T3. On viewing the page the boxes are checked or unchecked appropriately according to database table values. I am trying to determine the checked or unchecked states of these checkboxes and then writing it to the database on a button click. All of that is fine. My problem is the actual "accessing" of those checkboxes/their associated ID's. I have extensively researched and tried everything yet nothing seems to work. I'm sure I'm missing some little nuance. Here's my code (sorry the indenting is screwed up):

        Dim RecCountT As Integer = TNotify.Rows.Count
    For i = 0 to RecCountT - 1
    Dim strSQLNotifyT as String = "UPDATE dbo._PinCodes  SET TextOnOff = @TextOnOff  WHERE EmployeeID = @EmployeeID"
    Dim myCommand as New SqlCommand(strSQLNotifyT, Conn)
    
    Dim CheckBoxID
    CheckBoxID = "T" & i
    
    If CheckBoxID.Checked = True Then
    myCommand.Parameters.AddWithValue("@TextOnOff", "on")
    ElseIf CheckBoxID.Checked = False Then
    myCommand.Parameters.AddWithValue("@TextOnOff", "off")
    End If
    
    myCommand.Parameters.AddWithValue("@EmployeeID", TNotify.Rows(i)("EmployeeID").ToString())
    Conn.Open()
    myCommand.ExecuteNonQuery()
    Conn.Close()
    Next
user692942
  • 16,398
  • 7
  • 76
  • 175
smdevivo
  • 29
  • 7
  • if the checkbox is unchecked the value may not come through...only checked options are posted (It's an odd quirk... ) Maybe see this post for various solutions: https://stackoverflow.com/questions/1809494/post-unchecked-html-checkboxes – pcalkins Aug 12 '20 at 19:22

1 Answers1

0

Since I do not see the checkbox creation code and assuming the checkBox is created successully and added to the Controls collection, when you create the CheckBox, add:

yourCheckBox.ClientIDMode = ClientIDMode.Static

If this does not work, edit your post with more relevant code to replicate the issue.

Jamal
  • 398
  • 4
  • 9