Skip to content

Instantly share code, notes, and snippets.

@xpando
Created October 20, 2010 15:18
Show Gist options
  • Save xpando/636613 to your computer and use it in GitHub Desktop.
Save xpando/636613 to your computer and use it in GitHub Desktop.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Demo.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="_prevYearButton" Text="<<" OnClick="_prevYearButton_Click" runat="server" />
<asp:Button ID="_prevMonthButton" Text="<" OnClick="_prevMonthButton_Click" runat="server" />
<asp:Button ID="_nextMonthButton" Text=">" OnClick="_nextMonthButton_Click" runat="server" />
<asp:Button ID="_nextYearButton" Text=">>" OnClick="_nextYearButton_Click" runat="server" />
<asp:Label ID="_currentDateLabel" runat="server" />
</div>
</form>
</body>
</html>
using System;
namespace Demo
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
_currentDateLabel.Text = CurrentDate.ToString();
}
}
public DateTime CurrentDate
{
get
{
if (null == ViewState["CurrentDate"])
return DateTime.Now.Date;
return (DateTime)ViewState["CurrentDate"];
}
set
{
ViewState["CurrentDate"] = value;
}
}
protected void _nextMonthButton_Click(object sender, EventArgs e)
{
CurrentDate = CurrentDate.AddMonths(1);
_currentDateLabel.Text = CurrentDate.ToString();
}
protected void _prevMonthButton_Click(object sender, EventArgs e)
{
CurrentDate = CurrentDate.AddMonths(-1);
_currentDateLabel.Text = CurrentDate.ToString();
}
protected void _nextYearButton_Click(object sender, EventArgs e)
{
CurrentDate = CurrentDate.AddYears(1);
_currentDateLabel.Text = CurrentDate.ToString();
}
protected void _prevYearButton_Click(object sender, EventArgs e)
{
CurrentDate = CurrentDate.AddYears(-1);
_currentDateLabel.Text = CurrentDate.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment