Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Checked checkbox says not checked

Checked checkbox says not checked

Scheduled Pinned Locked Moved ASP.NET
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Baatezu
    wrote on last edited by
    #1

    Hello, I dynamically create a check box in each row of a table. (dynamically created rows) When I click a button to check the status of the check boxes, they all come back a not checked. This is how I add the check boxes ----- cell = New TableCell cell.Controls.Add(chkHeaderDelete_Array(HeaderLoop)) row.Cells.Add(cell) tblHeader.Rows.Add(row) ----- and I check them by ----- rowCtr = tblHeader.Rows.Count For ctr = 0 To rowCtr - 1 row = tblHeader.Rows(ctr) chkBox = row.Cells(0).Controls(0) If chkBox.Checked Then .... ----- And every check box in the table will come back as not checked. Is there anything I can do to make it properly recognize when check box is checked or not? Thanks The wisest of the wise may err. - Aeschylus

    C 1 Reply Last reply
    0
    • B Baatezu

      Hello, I dynamically create a check box in each row of a table. (dynamically created rows) When I click a button to check the status of the check boxes, they all come back a not checked. This is how I add the check boxes ----- cell = New TableCell cell.Controls.Add(chkHeaderDelete_Array(HeaderLoop)) row.Cells.Add(cell) tblHeader.Rows.Add(row) ----- and I check them by ----- rowCtr = tblHeader.Rows.Count For ctr = 0 To rowCtr - 1 row = tblHeader.Rows(ctr) chkBox = row.Cells(0).Controls(0) If chkBox.Checked Then .... ----- And every check box in the table will come back as not checked. Is there anything I can do to make it properly recognize when check box is checked or not? Thanks The wisest of the wise may err. - Aeschylus

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Basically, the problem is this. You dynamically create a checkbox, then your page posts back. After PageInit, but before PageLoad, your viewstate is restored, and the values stored in it are mapped to controls on the page. If your controls do not exist yet, then the viewstate for those controls are lost. You should override LoadViewState and before calling it, you should create your checkboxes there. They need to be in the same place, with the same name, every time, and then the viewstate will be restored. Christian Graus - Microsoft MVP - C++

      B 1 Reply Last reply
      0
      • C Christian Graus

        Basically, the problem is this. You dynamically create a checkbox, then your page posts back. After PageInit, but before PageLoad, your viewstate is restored, and the values stored in it are mapped to controls on the page. If your controls do not exist yet, then the viewstate for those controls are lost. You should override LoadViewState and before calling it, you should create your checkboxes there. They need to be in the same place, with the same name, every time, and then the viewstate will be restored. Christian Graus - Microsoft MVP - C++

        B Offline
        B Offline
        Baatezu
        wrote on last edited by
        #3

        Thank you. It works now thanks to your advice. The wisest of the wise may err. - Aeschylus

        C 1 Reply Last reply
        0
        • B Baatezu

          Thank you. It works now thanks to your advice. The wisest of the wise may err. - Aeschylus

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Glad to help - it's definately one of the most tricky areas to get right in ASP.NET. :-) Christian Graus - Microsoft MVP - C++

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups