Counting controls (very urgent)
-
hello, How do I count the number of textbox controls in a asp.net webpage thanks & regards Nagalakshmi
-
hello, How do I count the number of textbox controls in a asp.net webpage thanks & regards Nagalakshmi
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
-
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
Hi there, The sample code simply counts the number of the textboxes in the
Controls
collection of theform
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.