BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

How To Change Page Background Color With ASP.NET Server Side

To change background color of ASP.NET page you need to add bgcolor parameter to <body > tag. By default, body tag is not visible to server side code. First, you need to add runat="server" attribute and some ID to body tag, like this:

<body id="PageBody" runat="server">

After that, in code behind to change background color to some other (e.g. yellow), use this code:

[ C# ]

PageBody.Attributes.Add("bgcolor", "yellow");

[ VB.NET ]

PageBody.Attributes.Add("bgcolor", "yellow")

 

Note that, if you use ASP.NET 1.1 you need to declare protected variable in page class, like this:

[ C# ]

public class WebForm1 : System.Web.UI.Page
{
      protected HtmlGenericControl PageBody;
 
...
 
}

[ VB.NET ]

Public Class WebForm1
    Inherits System.Web.UI.Page
 
 
    Protected PageBody As HtmlGenericControl
 
    ...
End Class



Related articles:

1. How to set up an ASP.NET web site with IIS

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.