一款日期控件

80酷酷网    80kuku.com

  控件C#版:
using System;
using System.Web;
using System.Web.UI;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.Reflection;
using System.Text;

[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("A QuickStart Tutorial Assembly")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft QuickStart Tutorials")]
[assembly: AssemblyCopyright(" Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.1.*")]

namespace Acme
{
public class Calendar : Control, IPostBackEventHandler, IPostBackDataHandler
{
private String[] monthNames = new String[12];
private DateTime currentDate = DateTime.Now;
private String backColor = "#dcdcdc";
private String foreColor = "#eeeeee";

protected override void OnInit(EventArgs E)
{
Page.RegisterRequiresPostBack(this);

currentDate = DateTime.Now;

monthNames[0] = "January";
monthNames[1] = "February";
monthNames[2] = "March";
monthNames[3] = "April";
monthNames[4] = "May";
monthNames[5] = "June";
monthNames[6] = "July";
monthNames[7] = "August";
monthNames[8] = "September";
monthNames[9] = "October";
monthNames[10] = "November";
monthNames[11] = "December";
}

protected override void LoadViewState(Object viewState)
{
// If we've done a post-back, the old date will be available to us

if (null != viewState)
{
currentDate = DateTime.Parse((String) viewState);
}
}

public void RaisePostBackEvent(String eventArgument)
{
//Page.Response.Write("RaisePostBackEvent Called!!!");

if (eventArgument == null)
{
return;
}

// Keep track of old date (for event firing purposes)

DateTime oldDate = currentDate;

if (String.Compare("NavNextMonth", eventArgument, true, CultureInfo.InvariantCulture) == 0)
{
currentDate = currentDate.AddMonths(1);
}
else if (String.Compare("NavPrevMonth", eventArgument, true, CultureInfo.InvariantCulture) == 0)
{
currentDate = currentDate.AddMonths(-1);
}
else
{
int daySelected = Int32.Parse(eventArgument);
currentDate = new DateTime(currentDate.Year, currentDate.Month, daySelected);
}
}

protected override Object SaveViewState()
{
// Save CurrentDate out as view state for postback scenarios

return currentDate.ToString();
}

protected override void Render(HtmlTextWriter output)
{
if ((Page.Request.UserAgent != null) &&
(Page.Request.Browser.Browser.ToUpper(CultureInfo.InvariantCulture).IndexOf("IE") > -1) &&
(Double.Parse(Page.Request.Browser.Version) >= 5.5))
RenderUpLevel(output);
else
RenderDownLevel(output);
}

protected void RenderUpLevel(HtmlTextWriter output)
{
output.WriteLine("<input name='" + UniqueID + "_CurrentDate' id='" + UniqueID + "_CurrentDate' type=hidden>");
output.WriteLine("<span id='" + UniqueID + "'></span>");
output.WriteLine("<script language=jscript>drawcalendar('" + UniqueID + "', '" + currentDate.Year.ToString() + "/" + current

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: