Live Chat Icon For mobile
Live Chat Icon

How to set the background color of a web page using code behind?

Platform: ASP.NET| Category: Client Side Scripting


  1. In the body tag, add runat=’server’ and give the tag an id (e.g. id=’bodyID’).
  2. In the class definition in the code-behind, add

    Protected bodyID As System.Web.UI.HtmlControls.HtmlGenericControl


    protected  System.Web.UI.HtmlControls.HtmlGenericControl bodyID  ;
  3. In code, use the attributes collection to set the bgcolor attribute:

    bodyID.Attributes.Add('bgcolor', 'green')


    bodyID.Attributes.Add('bgcolor', 'green');

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.