DateTimeTextBox.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace DymWebForm.Aspx
  8. {
  9. internal class DateTimeTextBox: TextBox
  10. {
  11. protected override void OnPreRender(EventArgs e)
  12. {
  13. base.OnPreRender(e);
  14. this.MaxLength = this.IsContainTime ? 19 : 10;
  15. base.Attributes.Add("size", this.MaxLength.ToString());
  16. ScriptManager.RegisterClientScriptResource(this, this.GetType(), this.GetType().Namespace + ".Resources.Calendar.js");
  17. }
  18. protected override void Render(HtmlTextWriter writer)
  19. {
  20. base.Render(writer);
  21. string iconUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), this.GetType().Namespace + ".Resources.Calendar.Icon.Norm.bmp");
  22. string iconUrl2 = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), this.GetType().Namespace + ".Resources.Calendar.Icon.Hove.bmp");
  23. writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
  24. writer.AddAttribute(HtmlTextWriterAttribute.Src, iconUrl);
  25. writer.AddAttribute(HtmlTextWriterAttribute.Onclick, string.Format("new Calendar(null, null, 0).show(document.getElementById('{0}'));", this.ClientID));
  26. writer.AddAttribute("onmouseover", string.Format("this.src='{0}';", iconUrl2));
  27. writer.AddAttribute("onmouseout", string.Format("this.src='{0}';", iconUrl));
  28. writer.RenderBeginTag(HtmlTextWriterTag.Img);
  29. writer.RenderEndTag();
  30. }
  31. public bool IsContainTime
  32. {
  33. get
  34. {
  35. if (this.ViewState[this.UniqueID + ":IsContainTime"] == null)
  36. {
  37. return true; //the default value
  38. }
  39. return (bool)this.ViewState[this.UniqueID + ":IsContainTime"];
  40. }
  41. set
  42. {
  43. this.ViewState[this.UniqueID + ":IsContainTime"] = value;
  44. }
  45. }
  46. }
  47. }