Asp.Net 如何获取所有控件&如何获取指定类型的所有控件
一、
Asp.Net Page页面中访问所有控件的属性为:
Page.Controls
控件的结构是树结构。
二、获取指定类型所有控件实例:
1.递归方法定义:
- private void GetControlList<T>(ControlCollection controlCollection, List<T> resultCollection)
- where T : Control
- {
- foreach (Control control in controlCollection)
- {
- //if (control.GetType() == typeof(T))
- if (control is T) // This is cleaner
- resultCollection.Add((T)control);
- if (control.HasControls())
- GetControlList(control.Controls, resultCollection);
- }
- }
2.使用调用:
- List<Literal> allControls = new List<Literal>();
- GetControlList<Literal>(Page.Controls, allControls);
- foreach (var childControl in allControls)
- {
- //call for all controls of the page
- }
Asp.Net 如何获取所有控件&如何获取指定类型的所有控件的更多相关文章
- WPF中查找指定类型的父控件
/// <summary> /// 查找父控件 /// </summary> /// <typeparam name="T"></type ...
- delphi ----寻找控件,以字符串类型的名称控件
vari :Integer;beginfor i := 1 to 10 do(FindComponent('Edit'+inttostr(i)) as TEdit).Text := inttostr( ...
- monkeyrunner之坐标或控件ID获取方法(六)
Monkeyrunner的环境已经搭建完成,现在对Monkeyrunner做一个简介. Monkeyrunner工具提供了一套API让用户/测试人员来调用,调用这些api可以控制一个Android设备 ...
- .net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】
1.首先在前台dataGridview属性中增加onRowDataBound属性事件 2.然后在后台Observing_RowDataBound事件中增加代码 protected void Obser ...
- javascript客户端遍历控件与获取父容器对象
javascript客户端遍历控件与获取父容器对象示例代码 1,遍历也面中所有的控件function findControlAll() { var inputs=document. ...
- WPF silverlight获取子控件(获取DataTemplate里的子控件)
public static class VisualTreeExtensions { /// <summary> /// 获取父节点控件 /// </summary> /// ...
- NX二次开发-Block UI C++界面Specify Point(指定点)控件的获取(持续补充)
Specify Point(指定点)控件的获取 NX9+VS2012 #include <uf.h> #include <uf_ui.h> UF_initialize(); / ...
- NX二次开发-Block UI C++界面Face Collector(面收集器)控件的获取(持续补充 )
Face Collector(面收集器)控件的获取 NX9+VS2012 #include <uf.h> #include <uf_obj.h> UF_initialize() ...
- NX二次开发-Block UI C++界面Object Color Picker(对象颜色拾取器)控件的获取(持续补充)
Object Color Picker(对象颜色拾取器)控件的获取 NX9+VS2012 #include <uf.h> #include <uf_obj.h> UF_init ...
随机推荐
- ubuntu操作系统下载
原文网址:http://www.cyberciti.biz/linux-news/download-ubuntu-14-4-cd-dvd-iso-images/ Download of the day ...
- C#用xpath查找某节点
C#用xpath查找某节点 从根节点一直下来的相对路径才能确定Xpath的写法. /root/<节点1>/<节点2>//<@属性> Xpath是功能很强大的,但是也 ...
- Android 系统日期时间的获取
import java.text.SimpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月 ...
- Enum 枚举
一: 1. foreach (int val in Enum.GetValues(typeof(AppEnum.HarbourStatus))) { ddlStatus.Items.Add(new L ...
- BZOJ2301: [HAOI2011]Problem b 莫比乌斯反演
分析:对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 然后对于求这样单个的gcd(x,y)=k的, ...
- Android之parseSDKContent failed
由于之前安装ADT之后就一直报parseSDKContent failed的错误,具体的信息为:java.lang.NullPointerException. 此问题的情况为在Eclipse下,And ...
- eclipse简单注释规范
设置注释模板的入口: Window->Preference->Java->Code Style->Code Template Types/*** @ClassName: ${t ...
- cloudstack安装篇1-linux命令修改IP信息
方式一: ifconfig eth0 192.168.1.18 netmask 255.255.255.0 说明:该种方式可以使改变即时生效,重启后会恢复为原来的IP 方式二: vi ...
- PrintDbGrideh 打印数据
PrintDbGrideh1.BeforeGridText.Clear;//添加 PrintDbGrideh1.BeforeGridText.Add( '订单 '); PrintDBGridEh1.P ...
- ERROR hdfs.DFSClient: Failed to close file解决方法
14/04/11 17:59:44 ERROR hdfs.DFSClient: Failed to close file /wlan_out/_temporary/_attempt_local_000 ...