ASP.NET中的代码隐藏/样式表桥?在ASP.NET的代码隐藏中向css选择器添加样式?

ASP.NET中的代码隐藏/样式表桥?在ASP.NET的代码隐藏中向css选择器添加样式?,asp.net,stylesheet,bridge,Asp.net,Stylesheet,Bridge,我需要知道ASP.NET服务器端代码是否可以引用在给定页面上有效的样式表。在ASP.NET代码隐藏中,是否可以获取样式表中现有CSS选择器的引用?在服务器端代码隐藏中是否可以使用以下伪代码 MyPage.Stylesheets(0)("DIV#foo").Attributes("display").Value = "none" NOTE: Assume that <div id = 'foo'>lorem ipse...</div> has bee

我需要知道ASP.NET服务器端代码是否可以引用在给定页面上有效的样式表。在ASP.NET代码隐藏中,是否可以获取样式表中现有CSS选择器的引用?在服务器端代码隐藏中是否可以使用以下伪代码

     MyPage.Stylesheets(0)("DIV#foo").Attributes("display").Value = "none"


    NOTE:  Assume that <div id = 'foo'>lorem ipse...</div> has been injected
    into the DOM by javascript. There is no server side counterpart to the DIV.
    It was **not** part of the ASP.NET markup:  <div id="foo" runat="server"....
MyPage.Stylesheets(0)(“DIV#foo”).Attributes(“display”).Value=“无”
注意:假设lorem ipse。。。已经注射了
通过javascript进入DOM。没有与DIV对应的服务器端。

它不是ASP.NET标记的一部分:事实上,我找到了一种方法来实现这一点,尽管没有使用我期望的方法。Visual Studio不喜欢以下内容,但它可以工作:

  <style type="text/css" media="all">DIV#foo{<%= FooCSS %>}</style>

要做到这一点并不容易,除非它将runat=“server”添加到正在呈现的元素中,并将它们从服务器添加到DOM中。直接解析CSS不值得花费额外的处理,因为这可能会降低应用程序的速度。
         Public Readonly Property FooCSS as String
           Get
             Return "display:none"
           End Get
         End Property