2009/12/12

[ASP.Net]Dynamically assign your page's background image

I would like to change/assign a page's background image depends on some conditions, and here is what I did.
1.Assign an id to the body and add the runat="server" to it.

2.Add the following code to your code-behind (you can put it in the Page_Load event)
if (ConfigurationManager.ConnectionStrings["MyWebsite"].ConnectionString.Contains("test"))
body1.Style.Add("background-image", @"url(Images/test.jpg)");
else
body1.Style.Add("background-image", @"url(Images/production.jpg)");
Modify the if statement to meet your needs.

2009/12/02

[C# 2.0] Get and Check Daylight Saving Time (DST)

using System.Globalization;

public static DataTable GenerateDST(int startYear, int endYear)
{
  DataTable dt = new DataTable();
  //get the current timezone
  TimeZone oTimeZone = TimeZone.CurrentTimeZone;
  DaylightTime oDST;

  dt.Columns.Add("Year");
  dt.Columns.Add("Start Date");
  dt.Columns.Add("End Date");

  for (int i = startYear; i <= endYear; i++)
  {
    oDST = oTimeZone.GetDaylightChanges(i);
    dt.Rows.Add(oDST.Start.Year, oDST.Start.ToShortDateString(), oDST.End.ToShortDateString());
  }

  oTimeZone = null;
  oDST = null;

  return dt;
}