Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > MCSD > ASP.NET Controls Question

Reply
Thread Tools

ASP.NET Controls Question

 
 
Niranjan
Guest
Posts: n/a
 
      09-07-2004
Hello All,

I created a new ASP.NET web application and printed out the number of
controls in the page

Response.Write(this.Page.Controls.Count.ToString() );

It shows a count of 3 even though I did not add any controls to the
page. Could anyone explain why ?

Thanks !
 
Reply With Quote
 
 
 
 
Becky
Guest
Posts: n/a
 
      09-07-2004
Have you tried walking through your code? If you add your
page object to the watch window, you can open up the
Page.Controls collection and look at which controls are
inside.

The Form is actually a control inside the page, so even if
you haven't added any controls to the page, the Form will
still be there.

>-----Original Message-----
>Hello All,
>
>I created a new ASP.NET web application and printed out

the number of
>controls in the page
>
>Response.Write(this.Page.Controls.Count.ToString( ));
>
>It shows a count of 3 even though I did not add any

controls to the
>page. Could anyone explain why ?
>
>Thanks !
>.
>

 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      09-08-2004
Set a breakpoint in the Page load sub. Use the IDE to
explore the properties of the Page.Controls object.

>-----Original Message-----
>Hello All,
>
>I created a new ASP.NET web application and printed out

the number of
>controls in the page
>
>Response.Write(this.Page.Controls.Count.ToString( ));
>
>It shows a count of 3 even though I did not add any

controls to the
>page. Could anyone explain why ?
>
>Thanks !
>.
>

 
Reply With Quote
 
Satish R. Katika
Guest
Posts: n/a
 
      09-09-2004
i think you should try the following code to get the
Controls List contained in your WebPage.
__________________________________________________ _______

int iTotalControlCount = 0;
System.Text.StringBuilder sbControls = new
System.Text.StringBuilder("");

private void Page_Load(object sender, System.EventArgs e)
{
TotalControlCount(this);
Response.Write("Total Controls Count = " +
iTotalControlCount.ToString());
Response.Write(sbControls.ToString());
}

private void TotalControlCount(Control ctl)
{
iTotalControlCount++;
sbControls.Append("<br>" + ctl.ID + " -- " +
ctl.GetType().ToString());

if(ctl.HasControls())
{
foreach(Control eachCtl in this.Controls)
{
iTotalControlCount++;
sbControls.Append("<br>");
sbControls.Append(eachCtl.ID + " --
" + eachCtl.GetType().ToString());
ChildControlCount(eachCtl);
}
}
}

private void ChildControlCount(Control ctl)
{
if(ctl.HasControls())
{
foreach(Control eachCtl in ctl.Controls)
{
iTotalControlCount++;
sbControls.Append("<br>");
sbControls.Append(eachCtl.ID + " --
" + eachCtl.GetType().ToString());
ChildControlCount(eachCtl);
}
}
}
__________________________________________________ _______


>-----Original Message-----
>Hello All,
>
>I created a new ASP.NET web application and printed out

the number of
>controls in the page
>
>Response.Write(this.Page.Controls.Count.ToString( ));
>
>It shows a count of 3 even though I did not add any

controls to the
>page. Could anyone explain why ?
>
>Thanks !
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot Nathan Sokalski ASP .Net 4 09-05-2007 03:27 AM
IntelliSense on Web User Controls and Web Custom Controls Axel Dahmen ASP .Net 1 11-12-2003 06:12 AM
Multiple controls with the same ID '_ctl24' were found. Trace requires that controls have unique IDs Jeff Tolman ASP .Net 0 11-04-2003 09:53 PM
How to force the child controls OnClick event before the parent controls CreateChildControls method? Arulraja ASP .Net 3 10-17-2003 04:22 PM
HTML Controls and User controls trinitypete ASP .Net 6 06-26-2003 09:47 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57