I'm try get all controls in my page by Page.Controls
, but it is returning his Master Page
control only, how to can I get this content page controls?
<%@ Page Title="" Language="C#" MasterPageFile="~/Template/ManagerTemplate.Master" AutoEventWireup="true" CodeBehind="Cliente.aspx.cs" Inherits="SistemaPedido.Cadastro.Cliente" %>
My event
protected void Page_Load(object sender, EventArgs e)
{
Page.LoadComplete += (s, arg) =>
{
foreach (Control Control in Page.Controls)
{
Response.Write(Control.ClientID + "<br/>");
}
};
}
List<Control> lst_controls = new List<Control>();
public void btnClick()
{
RetrieveAllControls(this.Page);
foreach(Control contrl in lst_controls)
{
// all controls
}
}
public static void RetrieveAllControls(Control control)
{
foreach (Control ctr in control.Controls)
{
if (ctr != null)
{
lst_controls.add(ctr);
if (ctr.HasControls())
{
RetrieveAllControls(ctr, strID);
}
}
}
return null;
}
Maybe you can try the above :)
It will help if you rename this way: foreach (Control control in Page.Controls) to avoid confusion. Possibly you're not seeing the controls because of this?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.