ASP.NET Controls Question

Discussion in 'MCSD' started by Niranjan, Sep 7, 2004.

  1. Niranjan

    Niranjan Guest

    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, Sep 7, 2004
    #1
    1. Advertising

  2. Niranjan

    Becky Guest

    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, Sep 7, 2004
    #2
    1. Advertising

  3. Niranjan

    Guest Guest

    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 !
    >.
    >
    Guest, Sep 8, 2004
    #3
  4. 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, Sep 9, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fachmann
    Replies:
    1
    Views:
    1,430
    fred5152
    Dec 18, 2007
  2. thingy
    Replies:
    0
    Views:
    316
    thingy
    Nov 6, 2006
  3. Paul_V
    Replies:
    0
    Views:
    475
    Paul_V
    Sep 24, 2004
  4. london1919
    Replies:
    1
    Views:
    2,863
    Lawrence Garvin \(MVP\)
    Dec 8, 2008
  5. Osiris

    Asp.Net Custom Controls & Safari Compatibility

    Osiris, Jun 1, 2009, in forum: General Computer Support
    Replies:
    0
    Views:
    1,387
    Osiris
    Jun 1, 2009
Loading...

Share This Page