Display all controls on a page : Response « Page Lifecycle « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ControlTree" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
    <title>Controls</title>
</head>
<body>
    <div>
        <i>This is static HTML (not a web control).</i>
    </div>
    <form id="Controls" runat="server">
    <div>
            <asp:panel id="MainPanel" runat="server" Height="112px">
            <asp:Button id="Button1" runat="server" Text="Button1"/>
            <asp:Button id="Button2" runat="server" Text="Button2"/>
            <asp:Button id="Button3" runat="server" Text="Button3"/>
            <asp:Label id="Label1" runat="server" Width="48px">
              Name:</asp:Label>
            <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
            </asp:panel>
            <asp:Button id="Button4" runat="server" Text="Button4"/>
    
    </div>
    </form>
    <div>
        <i>This is static HTML (not a web control).</i>
    </div>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ControlTree : System.Web.UI.Page
{
  private void Page_Load(object sender, System.EventArgs e)
  {
    DisplayControl(Page.Controls, 0);
  }

  private void DisplayControl(ControlCollection controls, int depth)
  {
    foreach (Control control in controls)
    {
      Response.Write(new String('-', depth * 4) + "> ");
      Response.Write(control.GetType().ToString() + " - <b>" + control.ID + "</b><br/>");

      if (control.Controls != null)
      {
        DisplayControl(control.Controls, depth + 1);
      }
    }
  }

}








5.9.Response
5.9.1.Use Response.Write to output data from a database
5.9.2.Response.ContentType
5.9.3.Display all controls on a page
5.9.4.Use Response.Redirect to transfer to another aspx file (C#)
5.9.5.Submit a named parameter via POST
5.9.6.Displaying the HTTP headers collection in ASP.NET
5.9.7.Displaying URL information in ASP.NET
5.9.8.Response.AddCacheItemDependencies
5.9.9.Adding a cache dependency in ASP.NET
5.9.10.Response.AddFileDependencies
5.9.11.Response.AddFileDependency
5.9.12.Response.AppendHeader
5.9.13.Response.AppendToLog
5.9.14.Response.ApplyAppPathModifier
5.9.15.Response.BinaryWrite
5.9.16.Response.BufferOutput
5.9.17.Response.Expires
5.9.18.Response.ExpiresAbsolute
5.9.19.Response.Charset
5.9.20.Response.ClearContent
5.9.21.Response.ClearHeaders()
5.9.22.Response.ContentEncoding
5.9.23.Response.End()
5.9.24.Response.IsClientConnected
5.9.25.Response.Output
5.9.26.Response.PICS
5.9.27.Response.RemoveOutputCacheItem
5.9.28.Response.StatusCode
5.9.29.Response.SuppressContent
5.9.30.Response.Write
5.9.31.Response.WriteFile