一款日期控制項

來源:互聯網
上載者:User
控制項 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



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。