Enumerating through the Page Controls Demo

This demo illustrates iterating through the Controls collection.


A List of the Controls in the Controls Collection
System.Web.UI.LiteralControl -
System.Web.UI.WebControls.Label - lblControlList
System.Web.UI.LiteralControl -
System.Web.UI.HtmlControls.HtmlForm -
System.Web.UI.ResourceBasedLiteralControl -

What's your name?


Source Code
<%@ Page Language="C#" %>
<script runat="server">

    void Page_Load(Object sender, EventArgs e)
    {      
      foreach(Control c in Controls)
        lblControlList.Text += c.ToString() + " - " + c.ID + "<br>";
    }

</script>

<html>
<body>
<h1>Enumerating through the Page Controls Demo</h1>
This demo illustrates iterating through the <code>Controls</code> collection.
<p><hr><p>
    <b>A List of the Controls in the <code>Controls</code> Collection</b><br>
    <asp:label runat="server" id="lblControlList" />
    <p>
    <form runat="server">
        What's your name?
        <asp:textbox runat="Server" id="txtName" />
    </form>


[Return to the article]