Thursday, January 19, 2012

Loop through the controls in the Page

<script runat="server" language="C#">
  void Page_Load(Object sender, EventArgs e)
  {      
    foreach(Control X in Controls)
      lblControlList.Text += X.ToString() + " - " + X.ID + "<br>";
  }
</script>


<html>
<head>
</head>
<body>
    <b>Lista de Controles na  
    <code>Controls</code> Collection</b><br>
    <asp:label runat="server" id="lblControlList" />
    <p>
    <form runat="server">
        Nome?
        <asp:textbox runat="Server" id="txtName" />
    </form>
</body>
</html>

No comments: