zoukankan      html  css  js  c++  java
  • asp.net 用户控件直接取值

    如:有用户控件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();
    }

  • 相关阅读:
    redis乐观锁
    redis
    解决创建Redis容器没有conf配置文件
    redis缓存配置
    Docker架构
    Flask获取数据的一些方法
    Nginx正向代理、反向代理与负载均衡
    Sanic
    Dockerfile详解
    Centos7上安装docker
  • 原文地址:https://www.cnblogs.com/94cool/p/2035013.html
Copyright © 2011-2022 走看看