Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从服务器端asp.net设置css属性?_C#_Asp.net - Fatal编程技术网

C# 如何从服务器端asp.net设置css属性?

C# 如何从服务器端asp.net设置css属性?,c#,asp.net,C#,Asp.net,如何从服务器设置css(后台)属性?目前不起作用:( cs aspx html { 背景色:''; } 您可以试试 .aspx 假设您的样式标记位于元素中,将=更改为(背景色:”;)将runat=“server”添加到元素中,并在页面加载事件中调用Page.Header.DataBind()。您可以这样做 Page.Header.Controls.Add( new LiteralControl( @"<style type='text/css'>

如何从服务器设置css(后台)属性?目前不起作用:(

cs

aspx


html
{
背景色:'';
}
您可以试试

.aspx


假设您的样式标记位于
元素中,将
=
更改为
背景色:”;
)将
runat=“server”
添加到
元素中,并在页面加载事件中调用
Page.Header.DataBind()

您可以这样做

Page.Header.Controls.Add(
    new LiteralControl(
        @"<style type='text/css'>
                html
                {
                    background-color: red;

                }
                </style>
            "
        )
);
Page.Header.Controls.Add(
新文字控制(
@"
html
{
背景色:红色;
}
"
)
);

yourPageOrControlInstance.Styles[“background”]=“yellow blah”;

您是说它根本没有显示,还是没有显示您期望的颜色?您看到呈现的HTML中的值了吗?我会删除其中的单引号。而且,您是否在某处为MyBackgroundColor指定了值?您没有共享足够的代码。
<style type="text/css">
    html
    {
        background-color: '<%=MyBackgroundColor %>';
    }
</style>
<body id="body" runat="server">
...the body
body.Style["Background-Color"] = blue;//just example you can try using your method too
Page.Header.Controls.Add(
    new LiteralControl(
        @"<style type='text/css'>
                html
                {
                    background-color: red;

                }
                </style>
            "
        )
);