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. loop for textboxes

loop for textboxes

Scheduled Pinned Locked Moved ASP.NET
csharpquestion
12 Posts 4 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.
  • N N a v a n e e t h

    Iterate through the Page.Controls collection, check whether the control is a textbox, if yes set Enabled=false.

    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

    E Offline
    E Offline
    eyeseetee
    wrote on last edited by
    #3

    thanks for the reply I have this so far for (int x = 0; x < Page.Controls.Count; x++) { if (Page.Controls } How would I check if the control is a button and then set enable to false would it be something like Page.controls.Button.Enabled = false? thanks!!

    N 1 Reply Last reply
    0
    • E eyeseetee

      thanks for the reply I have this so far for (int x = 0; x < Page.Controls.Count; x++) { if (Page.Controls } How would I check if the control is a button and then set enable to false would it be something like Page.controls.Button.Enabled = false? thanks!!

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #4

      foreach (Control c in Page.Controls)
      {
      if(c is TextBox)
      c.Enabled = false;
      }

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      E 1 Reply Last reply
      0
      • N N a v a n e e t h

        foreach (Control c in Page.Controls)
        {
        if(c is TextBox)
        c.Enabled = false;
        }

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        E Offline
        E Offline
        eyeseetee
        wrote on last edited by
        #5

        Hi it says attrivute enabled is not recognised, I can make it invisible but not disabled what would be the reason for this? thanks so far! :)

        N 1 Reply Last reply
        0
        • E eyeseetee

          Hi it says attrivute enabled is not recognised, I can make it invisible but not disabled what would be the reason for this? thanks so far! :)

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #6

          Try this

          foreach (Control c in form1.Controls)
          {
          if (c is TextBox)
          (c as TextBox).Enabled = false;
          }

          where form1 is your form name.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

          E 1 Reply Last reply
          0
          • N N a v a n e e t h

            Try this

            foreach (Control c in form1.Controls)
            {
            if (c is TextBox)
            (c as TextBox).Enabled = false;
            }

            where form1 is your form name.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

            E Offline
            E Offline
            eyeseetee
            wrote on last edited by
            #7

            Hi The syntax built this time but none of the textboxes are disabled. Am I missing something? thanks

            N 1 Reply Last reply
            0
            • E eyeseetee

              Hi The syntax built this time but none of the textboxes are disabled. Am I missing something? thanks

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #8

              It's working here. Put break point and check it is executing.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

              E 1 Reply Last reply
              0
              • N N a v a n e e t h

                It's working here. Put break point and check it is executing.

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                E Offline
                E Offline
                eyeseetee
                wrote on last edited by
                #9

                ive got the code in the page _load, its def running but not working: foreach (Control c in form1.Controls) { if (c is TextBox) (c as TextBox).Enabled = false; }

                1 Reply Last reply
                0
                • E eyeseetee

                  Hi I have 20 different textboxes on a page I need to make them all disabled. IS there a way I can do this e.g. in a loop rather then writing out each textbox in the c# code? thanks inadvance! :)

                  P Offline
                  P Offline
                  Parwej Ahamad
                  wrote on last edited by
                  #10

                  I think you are doing little bit mistake in foreach line. Please try below code foreach (Control c in this.Page.Form.Controls ) { if (c is TextBox) ((WebControl)c).Enabled = false; }

                  Parwej Ahamad g.parwez@gmail.com

                  E P 2 Replies Last reply
                  0
                  • P Parwej Ahamad

                    I think you are doing little bit mistake in foreach line. Please try below code foreach (Control c in this.Page.Form.Controls ) { if (c is TextBox) ((WebControl)c).Enabled = false; }

                    Parwej Ahamad g.parwez@gmail.com

                    E Offline
                    E Offline
                    eyeseetee
                    wrote on last edited by
                    #11

                    Hi No sorry the controls are still enabled on the form, this is weird... I am using VWD.

                    1 Reply Last reply
                    0
                    • P Parwej Ahamad

                      I think you are doing little bit mistake in foreach line. Please try below code foreach (Control c in this.Page.Form.Controls ) { if (c is TextBox) ((WebControl)c).Enabled = false; }

                      Parwej Ahamad g.parwez@gmail.com

                      P Offline
                      P Offline
                      P Tagore Srinivas Dhanunjay
                      wrote on last edited by
                      #12

                      This code is working ;)

                      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