A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Posts Tagged ‘bgcolor’

Changing bgcolor of Page/Master Page dynamically+ASP.NET

Posted by kiranpatils on March 19, 2008

Hi, one of my colleague was struggling that how to set  value of Page’s background color in ASP.NET Code??

Problem:

Actually we want to set a page’s background color on Page_Load. and value changes everytime..how can i achieve it?

Solution: 

Nothing magic in it just two lines will do the same:

HtmlGenericControl bodytag = (HtmlGenericControl)Page.Master.FindControl(“body”);
bodytag.Style.Add(“background-color”,”#000999″);

for it my Master Page has body tag declared like this:

 <body ID=”body” runat=”server”/>

That’s it..

Posted in ASP.NET | Tagged: , | Leave a Comment »