Asp.Net 如何获取所有控件&如何获取指定类型的所有控件
2023-09-27 14:26:14 时间
一、
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 }
相关文章
- Nodejs进阶:服务端字符编解码&乱码处理
- 从.Net到Java学习第五篇——Spring Boot &&Profile &&Swagger2
- if(a==1 && a==2 && a==3) 结果为 true,怎么做到的?打破你的认知!
- IIS & Web.config redirects with rewrite rules - https, www, and more
- .net core compatibility windows & windows compatible Linux
- [IR] Tolerant Retrieval & Spelling Correction & Language Model
- UVA 1397 - The Teacher's Side of Math(高斯消元)
- ASP.NET Core – User Secrets & Azure Key Vault
- CSS & JS Effect – Dialog Modal
- ASP.NET Core – Logging & Serilog
- ASP.NET Core C# 反射 & 表达式树 (第二篇)
- ASP.NET Core C# 反射 & 表达式树 (第一篇)
- Asp.net core (学习笔记 路由和语言 route & language)
- 【GoLang】golang 交叉编译 实现&工具
- Java&.Net虚拟机精简(GreenJVM&GreenDotNet发布) .
- [.NET] 利用 async & await 的异步编程
- 流媒体压力测试rtmp&hls(含推流和拉流)
- gulp & webpack整合,鱼与熊掌我都要!
- 在.net(C#)中随机生成较深的颜色
- git学习------>git-rev-parse命令初识
- 我的Android进阶之旅------>Android关于Log的一个简单封装