gpt4 book ai didi

asp.net - 关于 WebControl.Style 属性的一些令人困惑的事情

转载 作者:行者123 更新时间:2023-11-27 22:37:11 26 4
gpt4 key购买 nike


1)

WebControl.Style ( MSDN ):

Controls have WebControl.Style property that returns a CssStyleCollection, which contains the HTML style attributes to render on the outer tag of the server control.

CssStyleCollection(MSDN):

Any style declared for a particular HTML server control is added to the collection when the containing Web Forms page is parsed.


一个)

  • 据我所知,在解析服务器控件(例如 GridView)之前,为 GridView 声明的所有样式(包括 GridView.RowStyle 和 GridView.BorderColor 等)都已添加到 GridView。样式集合(属于 CssStyleCollection 类型)?

  • 因此,当解析 GridView 时,Asp.Net 不会例如检查 GridView.RowStyle 属性然后相应地呈现相应的 html 样式属性,而是首先将 GridView 的所有样式传输到 CssStyleCollection,并且仅然后检查要为该控件呈现哪些 html 样式属性?


b) 如果我的上述假设是正确的(对此我表示怀疑)——为什么 Asp.Net 不简单地检查 GridView 的样式属性(如 GridView.BorderColor 等)并相应地呈现适当的 html 样式属性?将所有这些样式添加到 CssStyleCollection 然后才呈现适当的属性有什么意义?


2) WebControl.Style ( MSDN ):

Controls have WebControl.Style property that returns a CssStyleCollection, which contains the HTML style attributes to render on the outer tag of the server control.

我假设许多 Web 服务器控件(如 GridView)包含样式属性,这些属性将呈现在 html 控件的内部标记上。文本是否暗示这些属性未添加到 WebControl.Style 集合?如果不是,为什么不呢?


谢谢

最佳答案

Style 对象中的所有内容都得到适当呈现,或者至少在控件想要呈现它的地方呈现(例如,RowStyle 为 gridview 行呈现,而 EmptyDataStyle 为呈现空消息的容器呈现),所以它是直到控件呈现它。

如果你使用.NET反射器,它可以告诉你Style并没有继承自CssStyleCollection,而是有一个方法(GetStyleAttributes)可以将Style对象转换为CssStyleCollection集合,用于渲染。

HTH.

关于asp.net - 关于 WebControl.Style 属性的一些令人困惑的事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2001575/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com