如何在 ASP.NET 客户端和服务器端更改页面背景颜色
我试过
.color
{
PageBody.Attributes.Add("bgcolor", "yellow");
}
Run Code Online (Sandbox Code Playgroud)
写入 css 文件并用作 aclass="color"
如果要在运行时更改背景颜色,则需要在 runat="server"
那是
<body id="MasterBody" runat="server">
</body>
Run Code Online (Sandbox Code Playgroud)
如果要在母版页面加载中更改颜色,请在母版页面加载事件中添加以下代码
MasterBody.Attributes.Add("style", "background-color: #2e6095");
Run Code Online (Sandbox Code Playgroud)
此外,如果您想从指定母版页文件中的单个页面更改正文颜色,那么您首先需要从母版页中找到正文控件并在那里添加上面的代码,例如
System.Web.UI.HtmlControls.HtmlGenericControl MasterBody = (System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("MasterBody");
MasterBody.Attributes.Add("style", "background-color: #2e6095");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21691 次 |
| 最近记录: |