Click here to Skip to main content
15,896,118 members
Articles / Web Development / IIS

Rapid Web Application Development

Rate me:
Please Sign up or sign in to vote.
4.00/5 (5 votes)
27 Sep 200510 min read 204.1K   4.2K   86  
An article about the Multiformity Open Source project.
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using rasp.SQL;
using rasp.SQL.SQLStatement;
using rasp.SQL.DBInfo;

namespace rasp.HTML.Controls
{
	/// <summary>
	/// Contains 3 controls. The default Calendar control, a button and a textbox. The button will hide and/or show the 
	/// calendar control, and clicking a date in the calendar will place the selected date into the textbox.
	/// </summary>
	public class RaspCalendar : PlaceHolder, IWebControl {		
		private TextBox tb = new TextBox();
		private string VirtualName;
		/// <summary>
		/// Constructs the RaspCalendar with the given parameters.
		/// </summary>
		/// <param name="fi">A FieldInfo object that represents the field to be bound to the calendar.</param>
		/// <param name="val">The current value of the calendar.</param>
		/// <param name="CalendarChangeEvent">The event to be fired when a date is selected on the calendar, and should put the selected value into the corresponding textbox.</param>
		/// <param name="CalendarHideShowEvent">The event to be fired when the elipse button next to the textbox is clicked.</param>
		public RaspCalendar(FieldInfo fi, string val) {
			EnableViewState = true;
			VirtualName = fi.VirtualName;
			Text = val;
			tb.Width = new Unit(11,UnitType.Ex);
			ID = fi.ActualName;
			tb.ToolTip = fi.Description;
			Initialize();
		}

		

		#region Properties
		/// <summary>
		/// Gets or sets the selected date on the calendar, as well as the value for the textbox.
		/// </summary>
		/// <remarks>
		/// If you set the date to null, an empty string, or "1/1/0001", then the date will be set to "Today"
		/// </remarks>
		public string Text {
			get{
				return tb.Text;
			}
			set{
				if (value == null) {
					value = "";  
				} 
				if (value.Equals("1/1/0001") || value.Equals("")) {
					tb.Text = "[None]";
				} else {
					tb.Text = value;
				}
			}
		}
		/// <summary>
		/// Gets or sets the ID of the calendar, textbox and button.
		/// </summary>
		/// <remarks>
		/// The textbox's ID is actually the value returned in the getter, for the setter, since two controls cannot have the same ID,
		/// the textbox ID is set to the provided value, the calendars ID is set to the value + "_Calendar" and the buttons ID is
		/// set to the value + "_Button"
		/// </remarks>
		override public string ID {
			get {
				return tb.ID;
			}
			set {				
				tb.ID = VirtualName;
			}

		}
		/// <summary>
		/// Gets or sets the width of the textbox only.
		/// </summary>
		public Unit Width {
			get{
				return tb.Width;
			}
			set{
				tb.Width = value;
			}
		}
		#endregion

		#region Methods
		private void Initialize() {
			Controls.Add(tb);
			tb.ReadOnly = true;
			Controls.Add(this.CreateCalendarButton());
		}
		private Literal CreateCalendarButton() {
			Literal l = new Literal();
			l.Text = "<a href=\"javascript:calendarPopup('"+ this.ID +"', 250, 250);\"><img border=0 src="+ Constants.Images.Calendar + "></a>";
			return l;
		}
		/// <summary>
		/// This essentially hides the underlying TextBox control and returns a RaspHidden control.
		/// </summary>
		/// <returns>A RaspHidden control.</returns>
		public WebControl Hide() {
			return Tools.Hide(this);
		}
		#endregion
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions