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. Counting controls (very urgent)

Counting controls (very urgent)

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netquestion
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.
  • N Offline
    N Offline
    nagalakshmibasireddy
    wrote on last edited by
    #1

    hello, How do I count the number of textbox controls in a asp.net webpage thanks & regards Nagalakshmi

    M 1 Reply Last reply
    0
    • N nagalakshmibasireddy

      hello, How do I count the number of textbox controls in a asp.net webpage thanks & regards Nagalakshmi

      M Offline
      M Offline
      MihirV
      wrote on last edited by
      #2

      hi, like this,

      int count = 0;
      HtmlForm form = (HtmlForm)this.FindControl( "Form1" );
      
      if( form != null )
         foreach ( Control control in form.Controls )
            if ( control is TextBox )
               count++;
      
      Response.Write( count.ToString() );
      

      :) Confidence comes not from always being right, but from not fearing to be wrong..... Mihir.. -- modified at 0:52 Tuesday 17th January, 2006

      M 1 Reply Last reply
      0
      • M MihirV

        hi, like this,

        int count = 0;
        HtmlForm form = (HtmlForm)this.FindControl( "Form1" );
        
        if( form != null )
           foreach ( Control control in form.Controls )
              if ( control is TextBox )
                 count++;
        
        Response.Write( count.ToString() );
        

        :) Confidence comes not from always being right, but from not fearing to be wrong..... Mihir.. -- modified at 0:52 Tuesday 17th January, 2006

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        Hi there, The sample code simply counts the number of the textboxes in the Controls collection of the form element. To get the real number of the textboxes in the web page, you may need to recursively run the similar code to search for the textbox control in the control hierarchy instead of simply in the form's Controls collection.

        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