Results 1 to 2 of 2

Thread: Loop controls

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    20

    Loop controls

    I have a aspx page containing an aspanel called "Step3", in this panel there's 4 tables called "contact", "admin", "tech" and "billing" all runs as server controls.
    These tables are filled with "HtmlControls.HtmlInputText"(also running as server controls)
    I try to loop all HtmlControls inside this panel with this code:
    Code:
     
    foreach(Control ctrl in Step3.Controls) 
    { 
    Response.Write(ctrl.ID + " " + ctrl.GetType().ToString() + "<br>"); 
    }
    But all I get in output is

    System.Web.UI.LiteralControl
    contact System.Web.UI.HtmlControls.HtmlTable
    System.Web.UI.ResourceBasedLiteralControl
    admin System.Web.UI.HtmlControls.HtmlTable
    System.Web.UI.LiteralControl
    billing System.Web.UI.HtmlControls.HtmlTable
    System.Web.UI.LiteralControl
    tech System.Web.UI.HtmlControls.HtmlTable
    System.Web.UI.ResourceBasedLiteralControl
    P3Next System.Web.UI.WebControls.Button
    System.Web.UI.LiteralControl

    If I put a HtmlControl outside a table it shows up on the list. I've also tried to replace "Step3.Controls" with "admin.Controls" but then I only get the output:
    System.Web.UI.HtmlControls.HtmlTableRow

    Can anyone help me solve this problem? What do I need to do to loop all controls?

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    The problem is that your HtmlInputText are children of the panels:


    Code:
    foreach(Control ctrTopLvl in Step3.Controls) 
    { 
         Response.Write(ctrTopLvl.ID + " " + ctrTopLvl.GetType().ToString() + "<br>"); 
         foreach(Control ctrSecondLvl in ctrTopLvl.Controls) 
         { 
              Response.Write("     " + ctrSecondLvl.ID + " " + ctrSecondLvl.GetType().ToString() + "<br>"); 
         }
    }
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width