Go Back   Velocity Reviews > Newsgroups > MCSD
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

MCSD - ASP.NET Controls Question

 
Thread Tools Search this Thread
Old 09-07-2004, 08:50 PM   #1
Default ASP.NET Controls Question


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 !


Niranjan
  Reply With Quote
Old 09-07-2004, 10:44 PM   #2
Becky
 
Posts: n/a
Default ASP.NET Controls Question
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 !
>.
>



Becky
  Reply With Quote
Old 09-08-2004, 01:01 AM   #3
 
Posts: n/a
Default ASP.NET Controls Question
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
Old 09-09-2004, 08:15 PM   #4
Satish R. Katika
 
Posts: n/a
Default ASP.NET Controls Question
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 !
>.
>



Satish R. Katika
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Asp.Net Custom Controls & Safari Compatibility Osiris General Help Related Topics 0 06-01-2009 08:03 PM
ASP.NET Server controls on cross post back Fachmann Software 1 12-18-2007 08:48 PM
ASP.Net Project Structure Question koraykazgan Software 0 08-10-2007 08:23 AM
Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good God DVD Video 3 04-25-2005 04:19 PM
Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good Filthy Mcnasty DVD Video 0 04-25-2005 04:29 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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