⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textbox.cs

📁 不错的人事管理系统
💻 CS
字号:
/*
 *
 导读:
	1、 TextBox实现了System.Web.UI.IPostBackDataHandler接口,通过观察这个类可以获知
		System.Web.UI.IPostBackDataHandler接口的基本用法。

	2、 TextBox带有一个静态构造函数,用来初始化静态field EventTextChanged。
	
	3、 通过观察这个类就可以了解实现回传事件的基本方法
 * 
 */

using System;

namespace System.Web.UI.WebControls
{
	/// <summary>
	/// Summary description for TextBox.
	/// </summary>
	public class TextBox : System.Web.UI.WebControls.WebControl,
		System.Web.UI.IPostBackDataHandler
	{
		private static object EventTextChanged;

		static TextBox()
		{
			EventTextChanged = new object();
		}

		public TextBox() : base(System.Web.UI.HtmlTextWriterTag.Input)
		{
		}

		//重载OnPreRender,如果Page属性不为空、AutoPostBack和Enabled的值都为true时,
		//调用Page的RegisterPostBackScript()方法。
		protected override void OnPreRender(System.EventArgs e) //ok
		{
			base.OnPreRender(e);
			if(!(this.SaveTextViewState))
			{
				this.ViewState.SetItemDirty("Text", false);
			}
			if((this.Page != null)
				&& (this.AutoPostBack)
				&& (this.Enabled)
				)
			{
				this.Page.RegisterPostBackScript();
			}	
		}

		protected virtual void OnTextChanged(System.EventArgs e)
		{
			System.EventHandler V_0;
			V_0 = (System.EventHandler)this.Events[EventTextChanged];
			if(V_0 != null)
			{
				V_0(this, e);
			}
		}

		//重载Render方法,来实现TextArea和TextBox、Password不同的Client端代码
		protected override void Render(System.Web.UI.HtmlTextWriter writer)
		{
			this.RenderBeginTag(writer);
//			if(this.TextMode == System.Web.UI.WebControls.TextBoxMode.MultiLine)
//			{
//				System.Web.HttpUtility.HtmlEncode(this.Text, writer);
//			}
			this.RenderEndTag(writer);
		}

		protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) //ok
		{
			System.Web.UI.WebControls.TextBoxMode V_0;
			int V_1;
			string V_2;

			if(this.Page != null)
			{
				this.Page.VerifyRenderingInServerForm(this);
			}

			writer.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Name, this.UniqueID);

			V_0 = this.TextMode;

//			if(V_0 == System.Web.UI.WebControls.TextBoxMode.MultiLine)
//			{
//				V_1 = this.Rows;
//				if(V_1 > 0)
//				{
//					writer.AddAttribute(
//						System.Web.UI.HtmlTextWriterAttribute.Rows, 
//						V_1.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)
//						);
//				}
//
//				V_1 = this.Columns;
//				if(V_1 > 0)
//				{
//					writer.AddAttribute(
//						System.Web.UI.HtmlTextWriterAttribute.Cols, 
//						V_1.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)
//						);
//				}
//
//				if(!(this.Wrap))
//				{
//					writer.AddAttribute(
//						System.Web.UI.HtmlTextWriterAttribute.Wrap, 
//						"off"
//						);
//				}
//			}
//			else
//			{
//				if(V_0 == System.Web.UI.WebControls.TextBoxMode.SingleLine)
//				{
//					//line 0083
//					writer.AddAttribute(
//						System.Web.UI.HtmlTextWriterAttribute.Type, 
//						"text"
//						);
//
//					V_2 = this.Text;
//
//					if(V_2.Length > 0)
//					{
//						writer.AddAttribute(
//							System.Web.UI.HtmlTextWriterAttribute.Value, 
//							V_2
//							);
//					}
//				}
//				else if(V_0 == System.Web.UI.WebControls.TextBoxMode.Password)
//				{
//					writer.AddAttribute(
//						System.Web.UI.HtmlTextWriterAttribute.Type, 
//						"password"
//						);
//				}
//
//				//line 00c1
//				V_1 = this.MaxLength;
//				if(V_1 >0)
//				{
//					writer.AddAttribute(
//						System.Web.UI.HtmlTextWriterAttribute.Maxlength, 
//						V_1.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)
//						);
//				}
//
//				V_1 = this.Columns;
//				if(V_1 > 0)
//				{
//					writer.AddAttribute(
//						System.Web.UI.HtmlTextWriterAttribute.Size,
//						V_1.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)
//						);
//				}
//			}
			

			if(this.ReadOnly) //00ff
			{
				writer.AddAttribute(
					System.Web.UI.HtmlTextWriterAttribute.ReadOnly, 
					"readonly"
					);
			}

			base.AddAttributesToRender(writer);

			if(this.AutoPostBack)
			{
				if(this.Page != null)
				{
					writer.AddAttribute(
						System.Web.UI.HtmlTextWriterAttribute.Onchange,
						this.Page.GetPostBackClientEvent(this, "")
						);

					writer.AddAttribute(
						"language",
						"javascript"
						);
				}
			}
		}

		//私有实现System.Web.UI.IPostBackDataHandler的LoadPostData方法,当回传的数据和ViewState中的值一致时返回true,否则返回false。
		//如果返回true,RaisePostDataChangedEvent()方法会被调用(The Web Forms page framework)!
		bool System.Web.UI.IPostBackDataHandler.LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
		{
			string V_0;
			string V_1;

			V_0 = this.Text;
			V_1 = postCollection[postDataKey];

			if(!(V_0.Equals(V_1)))
			{
				this.Text = V_1;
				return(true);
			}

			return(false);
		}

		//响应回传事件
		void System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
		{
			this.OnTextChanged(System.EventArgs.Empty);
		}

		public virtual System.Web.UI.WebControls.TextBoxMode TextMode
		{
			get
			{
				object V_0;

				V_0 = this.ViewState["ReadOnly"];

				if(V_0 != null)
				{
					return (System.Web.UI.WebControls.TextBoxMode)V_0;
				}

				throw new Exception("");
//				return(System.Web.UI.WebControls.TextBoxMode.SingleLine);
			}
		}

		public virtual int Rows
		{
			get
			{
				object V_0;

				V_0 = this.ViewState["Rows"];

				if(V_0 != null)
				{
					return (int)V_0;
				}

				return(0);
			}
			set
			{
				if(value <0)
				{
					throw new System.ArgumentOutOfRangeException("value");
				}

				this.ViewState["Rows"] = value;
			}
		}

		public virtual int Columns
		{
			get
			{
				object V_0;

				V_0 = this.ViewState["Columns"];

				if(V_0 != null)
				{
					return (int)V_0;
				}

				return(0);
			}
			set
			{
				if(value <0)
				{
					throw new System.ArgumentOutOfRangeException("value");
				}

				this.ViewState["Columns"] = value;
			}
		}

		public virtual int MaxLength
		{
			get
			{
				object V_0;

				V_0 = this.ViewState["MaxLength"];

				if(V_0 != null)
				{
					return (int)V_0;
				}

				return(0);
			}
			set
			{
				if(value <0)
				{
					throw new System.ArgumentOutOfRangeException("value");
				}

				this.ViewState["MaxLength"] = value;
			}
		}

		public virtual bool Wrap
		{
			get
			{
				object V_0;

				V_0 = this.ViewState["Wrap"];

				if(V_0 != null)
				{
					return (bool)V_0;
				}

				return(true);
			}
			set
			{
				this.ViewState["Wrap"] = value;
			}
		}

		public virtual bool ReadOnly
		{
			get
			{
				object V_0;

				V_0 = this.ViewState["ReadOnly"];

				if(V_0 != null)
				{
					return (bool)V_0;
				}

				return(false);
			}
			set
			{
				this.ViewState["ReadOnly"] = value;
			}
		}

		public virtual bool AutoPostBack
		{
			get
			{
				object V_0;

				V_0 = this.ViewState["AutoPostBack"];

				if(V_0 != null)
				{
					return (bool)V_0;
				}

				return(false);
			}
			set
			{
				this.ViewState["AutoPostBack"] = value;
			}
		}

		public virtual string Text
		{
			get
			{
				string V_0;

				V_0 = (string)this.ViewState["Text"];

				if(V_0 != null)
				{
					return(V_0);
				}

				return(string.Empty);
			}
			set
			{
				this.ViewState["Text"] = value;
			}
		}

		private bool SaveTextViewState
		{
			get
			{
				if((this.Events[EventTextChanged] != null)
					&& (this.Enabled)
					&& (this.Visible)
					&& (this.GetType() ==typeof(System.Web.UI.WebControls.TextBox))
					)
				{
					return(true);
				}

				return(false);
			}
		}

		//TextChanged事件
		public event System.EventHandler TextChanged
		{
			add
			{
				this.Events.AddHandler(EventTextChanged, value);
			}
			remove
			{
				this.Events.RemoveHandler(EventTextChanged, value);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -