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. To loop thru controls on an ASP.NET page

To loop thru controls on an ASP.NET page

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netvisual-studio
3 Posts 3 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.
  • G Offline
    G Offline
    gamerPotatoe
    wrote on last edited by
    #1

    I know I'm posting alot today but the project I'm working on seems to be giving me a real taste of basic asp.net. I need to like run a loop on my asp.net page and disable a number of textboxes on the page within the loop. I know how it used to be done in good old vb6 but its not working in the exact same way on an asp.net page. I get stuck when I try to disable the control. My code flow is like this for each ctl in page.controls if typeof ctl is textbox ctl.enabled = false ' This line doesn't work infact during design time ' the IDE doesn't even recognise ".enabled" as ' a property of the control endif next I really need all the help I can get:^)

    J J 2 Replies Last reply
    0
    • G gamerPotatoe

      I know I'm posting alot today but the project I'm working on seems to be giving me a real taste of basic asp.net. I need to like run a loop on my asp.net page and disable a number of textboxes on the page within the loop. I know how it used to be done in good old vb6 but its not working in the exact same way on an asp.net page. I get stuck when I try to disable the control. My code flow is like this for each ctl in page.controls if typeof ctl is textbox ctl.enabled = false ' This line doesn't work infact during design time ' the IDE doesn't even recognise ".enabled" as ' a property of the control endif next I really need all the help I can get:^)

      J Offline
      J Offline
      Jeff Martin
      wrote on last edited by
      #2

      You need to cast the control as a textbox. I don't know VB, but in C# it's TextBox tb = (TextBox)ctl; tb.Enabled = false; I believe it is the CType() function in VB that you need. Jeff Martin My Blog

      1 Reply Last reply
      0
      • G gamerPotatoe

        I know I'm posting alot today but the project I'm working on seems to be giving me a real taste of basic asp.net. I need to like run a loop on my asp.net page and disable a number of textboxes on the page within the loop. I know how it used to be done in good old vb6 but its not working in the exact same way on an asp.net page. I get stuck when I try to disable the control. My code flow is like this for each ctl in page.controls if typeof ctl is textbox ctl.enabled = false ' This line doesn't work infact during design time ' the IDE doesn't even recognise ".enabled" as ' a property of the control endif next I really need all the help I can get:^)

        J Offline
        J Offline
        Javier Lozano
        wrote on last edited by
        #3

        Here's the code for finding the controls on the page: For Each ctrl As WebControl In Page.Controls If TypeOf ctrl Is TextBox Then Dim txtBox As TextBox = DirectCast(ctrl, GetType(TextBox)) txtBox.Enabled = True End If Next If you have any questions, let me know. ~Javier Lozano (blog)

        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