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

Yes

  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
    VB.NET

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

    C#

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

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

    C#

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

Share with

Related FAQs

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

Please submit your question and answer.