asp.net 用户控件直接取值
2011-05-03 10:34
169 查看
如:有用户控件header、affiche,
在affiche中获取header的值(前提这些值必须public)
在affiche.cs中加入
多个属性值:
Page p = this.Parent.Page; UserControl uc = p.FindControl("header1") as UserControl;
Type pageType = uc.GetType();
FieldInfo[] myFields = pageType.GetFields(BindingFlags.Public | BindingFlags.Instance);
for (int i = 0; i < myFields.Length; i++)
{
Response.Write(string.Format("The value of {0} is: {1}", myFields[i].Name, myFields[i].GetValue(uc)));
}
单个属性值:
Page p = this.Parent.Page;
UserControl uc = p.FindControl("header1") as UserControl;
Type pageType = uc.GetType();
FieldInfo field = pageType.GetField("cityId", BindingFlags.Public | BindingFlags.Instance);
if (field != null)
{
CityId = field.GetValue(uc).ToString();
}
在affiche中获取header的值(前提这些值必须public)
在affiche.cs中加入
多个属性值:
Page p = this.Parent.Page; UserControl uc = p.FindControl("header1") as UserControl;
Type pageType = uc.GetType();
FieldInfo[] myFields = pageType.GetFields(BindingFlags.Public | BindingFlags.Instance);
for (int i = 0; i < myFields.Length; i++)
{
Response.Write(string.Format("The value of {0} is: {1}", myFields[i].Name, myFields[i].GetValue(uc)));
}
单个属性值:
Page p = this.Parent.Page;
UserControl uc = p.FindControl("header1") as UserControl;
Type pageType = uc.GetType();
FieldInfo field = pageType.GetField("cityId", BindingFlags.Public | BindingFlags.Instance);
if (field != null)
{
CityId = field.GetValue(uc).ToString();
}
相关文章推荐
- ASP.NET页面上直接放置用户控件WebUserControl1时的事件顺序
- ASP.NET(C#)中将TextBox控件的Readonly属性设置为True时后台直接取值取不到的解决方案
- ASP.NET 直接访问用户控件
- ASP.NET--------Web用户控件
- ASP.NET缓存:用户控件缓存
- ASP.NET GridView动态显示隐藏列,并保存客户的配置(用户控件Cookie版)
- ASP.NET中DropDownList控件的简单使用--DDL绑定数据库表中值,选择DDL中值直接检索数据
- [ASP.NET] User Control,用户控件的四篇入门文章
- 牛腩购物13: 整合用户资料修改 用户修改密码 asp.net登陆控件的使用(登录前 登陆后) 显示登录名 显示注销按钮
- [导入]ASP.NET重用代码技术 - 用户控件技术
- 创建模板化的 ASP.NET 用户控件
- 将web窗体页文件(test.aspx)转换成用户控件文件(test.ascx)_asp.net技巧
- 农民伯伯--关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- Asp.net动态加载用户自定义控件,并转换成HTML代码[转]
- 解决Asp.net中翻页问题的自定义用户控件
- asp.net用户控件事件处理
- ASP.NET~用户控件优化的登陆demo
- Asp.net中翻页问题的自定义用户控件
- asp.net 中 用户控件
- Asp.net 2.0 自定义控件开发专题讲解[为用户控件增加DataSource属性, 能够自动识别不同数据源](示例代码下载)