如何使用反射读取webcontrol的样式[" display"]属性的值 [英] how to read value of style["display"] property of webcontrol using reflection

查看:82
本文介绍了如何使用反射读取webcontrol的样式[" display"]属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的页面上有一些用户控件和一些网页控件。要使用反射读取每个控件的Visibility属性,我在下面写了一行:

Hi all,

I have some user controls and some web controls on my page. To read the Visibility property of the each control using reflection I wrote below line :

Object v;
if (control.GetType().GetProperty("Visible") != null)
     v = control.GetType().GetProperty("Visible").GetValue(control, null);





但我怎么能 Style [display]的值使用反射的每个控件的属性



提前谢谢。



but how can I read the value of Style["display"] attribute of each control using reflection?

Thanks in advance.

推荐答案

Hi Patrik



Hi Patrik

Style  is of type CssStyleCollection

,你无法从反射中获取值..

你可以从样式名称或键名访问客户端属性和值





代码背后你可以通过

, you cant get the values from reflection..
you can access the client side properties and values from the style name or key name


in code behind u can access the client side style by

var display = txtbox.Style["display"];


必须将属性作为我们要查找的键的样式属性应用于它。



然后使用下面的代码来获取它。



Style property with the attribute as a key we are looking for must be applied to it.

Then use below code to get it.

var styleProp = control.GetType().GetProperty("Style");
            if (styleProp != null)
            {
                var styleCollection = styleProp.GetValue(control, null) as CssStyleCollection;
                var value = styleCollection["display"];
            }


这篇关于如何使用反射读取webcontrol的样式[" display"]属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆