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. ASP.Net HTML form postback question

ASP.Net HTML form postback question

Scheduled Pinned Locked Moved ASP.NET
questioncsharphtmlasp-net
6 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.
  • D Offline
    D Offline
    davebarkshire
    wrote on last edited by
    #1

    I have an ASP.Net form that has some HTML checkboxes which are dynamically added to the form. I use the ID to identify them but they are generated from data so are different every time. How can I see these checkboxes when I post back? I've tried Request.Form.Controls.Count and see that there are several HTML controls, but I'd like to be able to see the HTML ID and value of these controls. Ideally it would be by using a foreach loop. I can identify them by their ID as the ID starts with the string 'chk'. Am I missing something here? Thanks in advance - Dave

    P 1 Reply Last reply
    0
    • D davebarkshire

      I have an ASP.Net form that has some HTML checkboxes which are dynamically added to the form. I use the ID to identify them but they are generated from data so are different every time. How can I see these checkboxes when I post back? I've tried Request.Form.Controls.Count and see that there are several HTML controls, but I'd like to be able to see the HTML ID and value of these controls. Ideally it would be by using a foreach loop. I can identify them by their ID as the ID starts with the string 'chk'. Am I missing something here? Thanks in advance - Dave

      P Offline
      P Offline
      PerthCoder
      wrote on last edited by
      #2

      Off the top of my head Dave, I'm sure you can do the following... Request.Form.Item("chk???") Where ??? is your ID. That will give you access to the value of those controls on postback. HTH Chris.

      D 1 Reply Last reply
      0
      • P PerthCoder

        Off the top of my head Dave, I'm sure you can do the following... Request.Form.Item("chk???") Where ??? is your ID. That will give you access to the value of those controls on postback. HTH Chris.

        D Offline
        D Offline
        davebarkshire
        wrote on last edited by
        #3

        The problem is that I don't know what the number will be. I need to iterate through all controls that have been posted back and if their id starts with 'chk' then that is the data that I want to process.

        P 1 Reply Last reply
        0
        • D davebarkshire

          The problem is that I don't know what the number will be. I need to iterate through all controls that have been posted back and if their id starts with 'chk' then that is the data that I want to process.

          P Offline
          P Offline
          PerthCoder
          wrote on last edited by
          #4

          Ok, then perhaps something like... For Each tmpItem As Item In Request.Forms.Item If tmpItem.toString.IndexOf("chk") > 0 Then 'do something EndIf Next Might be what you are looking for? I hope I'm on the right track here. /chris

          D 1 Reply Last reply
          0
          • P PerthCoder

            Ok, then perhaps something like... For Each tmpItem As Item In Request.Forms.Item If tmpItem.toString.IndexOf("chk") > 0 Then 'do something EndIf Next Might be what you are looking for? I hope I'm on the right track here. /chris

            D Offline
            D Offline
            davebarkshire
            wrote on last edited by
            #5

            Chris Unfortunately there is no member under Request called Forms. I do have a member called Form but it doesn't have an Items collection. (Not in C# anyway). I do seem to have cracked it though. Here is what I found... int intItemId; // Loop for each key in the request form foreach (string strKey in Request.Form.Keys) { // Is this a checkbox key? if (strKey.IndexOf("chk") > -1) // Yes { // Get the id of the checked data item intItemId = Convert.ToInt32( strKey.Substring(strKey.IndexOf("chk") + 3) ); // The user has selected item intItemId. Process that here... } }// end foreach key

            P 1 Reply Last reply
            0
            • D davebarkshire

              Chris Unfortunately there is no member under Request called Forms. I do have a member called Form but it doesn't have an Items collection. (Not in C# anyway). I do seem to have cracked it though. Here is what I found... int intItemId; // Loop for each key in the request form foreach (string strKey in Request.Form.Keys) { // Is this a checkbox key? if (strKey.IndexOf("chk") > -1) // Yes { // Get the id of the checked data item intItemId = Convert.ToInt32( strKey.Substring(strKey.IndexOf("chk") + 3) ); // The user has selected item intItemId. Process that here... } }// end foreach key

              P Offline
              P Offline
              PerthCoder
              wrote on last edited by
              #6

              Ahh, C#, I'm not familiar with the differences between C# and VB.NET Glad you solved the problem :)

              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