Monday, March 31, 2008

Copyright Method

Create new web project and in Default.asp add lable (Id=lblCopyright)

and in Default.aspx.cs

public string DynamicCopyright(string YearSiteCreated)
{
string DynamicCopyrightYear;
//Is the current year equal to the year the site was created?
if (DateTime.Now.Year.ToString() != YearSiteCreated)
{
//If not then concatenate year created and current year
DynamicCopyrightYear = YearSiteCreated + "-" + DateTime.Now.Year.ToString();
}
else
{
DynamicCopyrightYear = YearSiteCreated;
}

string Copyright = "Copyright © " + DynamicCopyrightYear + ". All rights reserved.";
return Copyright;
}

protected void Page_Load(object sender, System.EventArgs e)
{
lblCopyright.Text = DynamicCopyright(2006);
//Use the created year as parameter
}

No comments: