| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- /**
- * Namespace: System.Web.UI.WebControls
- * Class: TextBox
- *
- * Author: Gaurav Vaish
- * Maintainer: [email protected]
- * Contact: <[email protected]>, <[email protected]>
- * Implementation: yes
- * Status: 80%
- *
- * (C) Gaurav Vaish (2002)
- */
- using System;
- using System.Collections.Specialized;
- using System.Web;
- using System.Web.UI;
- namespace System.Web.UI.WebControls
- {
- public class TextBox : WebControl, IPostBackDataHandler
- {
- private static readonly object TextChangedEvent = new object();
-
- public TextBox(): base(HtmlTextWriterTag.Input)
- {
- }
-
- public virtual bool AutoPostBack
- {
- get
- {
- object o = ViewState["AutoPostBack"];
- if(o!=null)
- return (bool)o;
- return false;
- }
- set
- {
- ViewState["AutoPostBack"] = value;
- }
- }
-
- public virtual int Columns
- {
- get
- {
- object o = ViewState["Columns"];
- if(o != null)
- return (int)o;
- return 0;
- }
- set
- {
- ViewState["Columns"] = value;
- }
- }
-
- public virtual int MaxLength
- {
- get
- {
- object o = ViewState["MaxLrngth"];
- if(o != null)
- return (int)o;
- return 0;
- }
- set
- {
- ViewState["MaxLrngth"] = value;
- }
- }
-
- public virtual bool ReadOnly
- {
- get
- {
- object o = ViewState["ReadOnly"];
- if(o != null)
- return (bool)o;
- return false;
- }
- set
- {
- ViewState["ReadOnly"] = value;
- }
- }
-
- public virtual int Rows
- {
- get
- {
- object o = ViewState["Rows"];
- if(o != null)
- return (int)o;
- return 0;
- }
- set
- {
- ViewState["Rows"] = value;
- }
- }
-
- public virtual string Text
- {
- get
- {
- object o = ViewState["Text"];
- if(o != null)
- return (string)o;
- return String.Empty;
- }
- set
- {
- ViewState["Text"] = value;
- }
- }
-
- public virtual TextBoxMode TextMode
- {
- get
- {
- object o = ViewState["TextMode"];
- if(o != null)
- return (TextBoxMode)o;
- return TextBoxMode.SingleLine;
- }
- set
- {
- if(!Enum.IsDefined(typeof(TextBoxMode), value))
- {
- throw new ArgumentException();
- }
- ViewState["TextMode"] = value;
- }
- }
-
- public virtual bool Wrap
- {
- get
- {
- object o = ViewState["Wrap"];
- if(o != null)
- return (bool)o;
- return false;
- }
- set
- {
- ViewState["Wrap"] = value;
- }
- }
-
- public event EventHandler TextChanged
- {
- add
- {
- Events.AddHandler(TextChangedEvent, value);
- }
- remove
- {
- Events.RemoveHandler(TextChangedEvent, value);
- }
- }
-
- protected override HtmlTextWriterTag TagKey
- {
- get
- {
- if(TextMode == TextBoxMode.MultiLine)
- {
- return HtmlTextWriterTag.Textarea;
- }
- return HtmlTextWriterTag.Input;
- }
- }
-
- [MonoTODO("Check_Value_of_Text_Potential_Bug_In_MS_Implementation")]
- protected override void AddAttributesToRender(HtmlTextWriter writer)
- {
- if(Page != null)
- {
- Page.VerifyRenderingInServerForm(this);
- }
- writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
- if(TextMode == TextBoxMode.MultiLine)
- {
- if(Rows > 0)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Rows, Rows.ToString(NumerFormatInfo.InvariantInfo));
- }
- if(Columns > 0)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Cols, Columns.ToString(NumerFormatInfo.InvariantInfo));
- }
- if(!Wrap)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Wrap, "off");
- }
- } else
- {
- if(TextMode == TextBoxMode.Password)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Type, "password");
- } else
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
- }
- if(MaxLength > 0)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, MaxLength.ToString(NumberFormatInfo.InvariantInfo));
- }
- if(Columns > 0)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Size, Columns.ToString(NumerFormatInfo.InvariantInfo));
- }
- }
- writer.AddAttribute(HtmlTextWriterAttribute.Value, Text);
- if(ReadOnly)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "readonly");
- }
- base.AddAttributesToRender(writer);
-
- if(AutoPostBack && Page != null)
- {
- writer.AddAttribute(HtmlTextWriterAttribute.Onchange, Page.GetPostBackClientEvent(this, ""));
- writer.AddAttribute("language", "javascript");
- }
- }
-
- protected override void AddParsedSubObject(object obj)
- {
- if(obj is LiteralControl)
- {
- Text = ((LiteralControl)obj).Text;
- return;
- }
- throw new HttpException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "TextBox", GetType().Name.ToString()));
- }
-
- [MonoTODO("OnPreRender")]
- protected override void OnPreRender(EventArgs e)
- {
- OnPreRender(e);
- throw new NotImplementedException();
- }
-
- protected virtual void OnTextChanged(EventArgs e)
- {
- if(Events != null)
- {
- EventHandler eh = (EventHandler)(Events[TextChangedEvent]);
- if(eh != null)
- eh(this, e);
- }
- }
-
- [MonoTODO("Encode_Text")]
- protected override void Render(HtmlTextWriter writer)
- {
- RenderBeginTag(writer);
- //TODO: if(TextMode == MultiLine) { Encode(Text) and writeTo(writer) }
- RenderEndTag(writer);
- throw new NotImplementedException();
- }
-
- bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
- {
- if(postCollection[postDataKey] != Text)
- {
- Text = postCollection[postDataKey];
- return true;
- }
- return false;
- }
-
- void IPostBackDataHandler.RaisePostDataChangedEvent()
- {
- OnTextChanged(EventArgs.Empty);
- }
- }
- }
|