Reputation: 5325
In one .aspx webpage I have 2 contacts details in two different <div> like below
<div id="primaryContact">
Name - betty quay
Cell - 9867452389
designation - Build
</div>
<div id="secondryContact">
Name - francesco maitire
Cell - 9867452389
designation - Build
</div>
Here I want to show each div on alternate day of a week. How can I do so, using ASP.NET or Javascript?
Upvotes: 0
Views: 138
Reputation: 741
You can do it in C# like this:
protected void Page_Load(object sender, EventArgs e)
{
ShowContactAlternate();
}
private void ShowContactAlternate()
{
if ((int)DateTime.Now.DayOfWeek % 2 == 0)
primaryContact.Visible = true;
else
secondaryContact.Visible = true;
}
Also make sure that you change your markup to something like this and add runat="server
and Visible="False"
attributes to divs":
<div id="primaryContact" runat="server" Visible="False"> Name - betty quay Cell - 9867452389 designation - Build </div>
<div id="secondryContact" runat="server" Visible="False"> Name - francesco maitire Cell - 9867452389 designation - Build </div>
EDIT:
If you want to alternate every week you can do it like this probably:
Create this helper function:
private int GetWeekOfYear(DateTime date)
{
return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date,
CalendarWeekRule.FirstFourDayWeek,
DayOfWeek.Monday);
}
And you can use it in your if statement inside ShowContactAlternate
line this:
if (GetWeekOfYear(DateTime.Now) % 2 == 0)
As every year has 52 weeks you have to be sure that you don't run in to trouble every new year. It shouldn't be a problem to solve.
Upvotes: 3