mytextbox.cs

来自「Professional ASP.NET source code」· CS 代码 · 共 58 行

CS
58
字号
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

namespace WroxControls 
{

	// This control renders out three root element HTML elements and thus
	// overrides the Render method
	
   public class MyTextBox : WebControl,
								    IPostBackDataHandler
   {
		
   	public MyTextBox() : base ("input")
		{
		}


		public event EventHandler TextChanged;

		string _value;

		public string Text
      {
         get { return _value; }
      }
		
		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
				base.AddAttributesToRender(writer);
            writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);

            writer.AddAttribute(HtmlTextWriterAttribute.Type, "input" );
				if ( _value != null )
					writer.AddAttribute( "value", _value );
		}

      bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) 
		{
			_value = postCollection[postDataKey];

			return true;
		}

		void IPostBackDataHandler.RaisePostDataChangedEvent() 
		{

			if ( TextChanged != null )
				TextChanged( this, EventArgs.Empty );

      }

   }
};

⌨️ 快捷键说明

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