A Date control

Source: Internet
Author: User
Tags datetime tostring
Control C # version:
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 would 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 () + "/" + Curren T



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.