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. General Programming
  3. C#
  4. help for enabled property

help for enabled property

Scheduled Pinned Locked Moved C#
sysadminhelptutorial
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.
  • V Offline
    V Offline
    vamsimohan21
    wrote on last edited by
    #1

    There are some set of server controls its property enabled= may be true or false,now in code behind how to find its current state and i am getting the controls id during runtime like this foreach(Control c in form1.Controls) { ............ } and also there is no property like (c.Enabled) to check

    Thanks In Advance

    C 1 Reply Last reply
    0
    • V vamsimohan21

      There are some set of server controls its property enabled= may be true or false,now in code behind how to find its current state and i am getting the controls id during runtime like this foreach(Control c in form1.Controls) { ............ } and also there is no property like (c.Enabled) to check

      Thanks In Advance

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

      vamsimohan21 wrote:

      foreach(Control c in form1.Controls) { ............ }

      A web form has a Controls collection, the trick is that it's a tree, so you need to recurse over it.

      Christian Graus - C++ MVP

      V 1 Reply Last reply
      0
      • C Christian Graus

        vamsimohan21 wrote:

        foreach(Control c in form1.Controls) { ............ }

        A web form has a Controls collection, the trick is that it's a tree, so you need to recurse over it.

        Christian Graus - C++ MVP

        V Offline
        V Offline
        vamsimohan21
        wrote on last edited by
        #3

        Thank sir for that and i tried with that but not got any solution can u just pls tell me any sample code and also how to know whether the control is enabled or in disabled state during runtime

        Thanks In Advance

        C 1 Reply Last reply
        0
        • V vamsimohan21

          Thank sir for that and i tried with that but not got any solution can u just pls tell me any sample code and also how to know whether the control is enabled or in disabled state during runtime

          Thanks In Advance

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

          Web controls do in fact have an Enabled property. I just checked. Maybe you need to post your code ?

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          V 1 Reply Last reply
          0
          • C Christian Graus

            Web controls do in fact have an Enabled property. I just checked. Maybe you need to post your code ?

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            V Offline
            V Offline
            vamsimohan21
            wrote on last edited by
            #5

            protected void Button1_Click1(object sender, EventArgs e) { foreach(Control c in mainform.Controls) { if (String.Compare(c.GetType().ToString(), "System.Web.UI.LiteralControl") == 1) { (//HERE I HAVE TO CHECK WHETHER THE CURRENT CONTROL IS IN ENABLED/DISABLED STATE) if (c.Enabled) //Error 4 'System.Web.UI.Control' does not contain a definition for 'Enabled' C:\Documents and Settings\vamsi\My Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs 86 23 C:\...\WebSite1\ { ................. } } } The above is the error i am reciving sir

            THANKS IN ADVANCE

            C 1 Reply Last reply
            0
            • V vamsimohan21

              protected void Button1_Click1(object sender, EventArgs e) { foreach(Control c in mainform.Controls) { if (String.Compare(c.GetType().ToString(), "System.Web.UI.LiteralControl") == 1) { (//HERE I HAVE TO CHECK WHETHER THE CURRENT CONTROL IS IN ENABLED/DISABLED STATE) if (c.Enabled) //Error 4 'System.Web.UI.Control' does not contain a definition for 'Enabled' C:\Documents and Settings\vamsi\My Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs 86 23 C:\...\WebSite1\ { ................. } } } The above is the error i am reciving sir

              THANKS IN ADVANCE

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

              vamsimohan21 wrote:

              if (String.Compare(c.GetType().ToString(), "System.Web.UI.LiteralControl") == 1)

              What on earth is this ?  It's a mess. if (c is LiteralControl) {   // etc }

              vamsimohan21 wrote:

              //Error 4 'System.Web.UI.Control' does not contain a definition for 'Enabled'

              Perhaps you need to have a derived class to have that property ? LiteralControl lc = c as LiteralControl; if (lc != null & lc.Enabled) {    // Whatever } This still won't work, unless you just didn't bother to post the code that causes it to be recursive, but I don't see how it can be.

              Christian Graus - C++ MVP

              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