当TextBox TextChanged事件被触发时?

我的问题是:

我们知道ViewState不负责存储和恢复TextBox,CheckBox等控件的值。 这是通过LoadPostData()方法来实现IPostBackDataHandler接口的控件。

并且我们也知道在Load阶段之后,会发生RaisePostBackEvent阶段并引发相应的事件,如Button Click或如果TextBox中的Text更改,则会触发其TextChanged事件。

那么,如果ViewState不对此负责,以及哪种机制实际触发TextBox TextChanged事件,系统如何跟踪文本是否已更改?

到目前为止我真的很困惑。

提前致谢。

我认为它正在以这种方式工作:

TextBox控件实现IPostBackDataHandler而不是IPostBackEventHandler,因为它的文本状态触发了它。 因此,如果在确定的publishValue中发生任何更改

if (presentValue == null || !presentValue.Equals(postedValue)) { Text = postedValue; return true; } 

部分然后它返回true并继续执行,最后TextChanged被触发。 Pff令人困惑,但看起来很容易。

 using System; using System.Web; using System.Web.UI; using System.Collections; using System.Collections.Specialized; namespace CustomWebFormsControls { [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] public class MyTextBox: Control, IPostBackDataHandler { public String Text { get { return (String) ViewState["Text"]; } set { ViewState["Text"] = value; } } public event EventHandler TextChanged; public virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) { String presentValue = Text; String postedValue = postCollection[postDataKey]; if (presentValue == null || !presentValue.Equals(postedValue)) { Text = postedValue; return true; } return false; } public virtual void RaisePostDataChangedEvent() { OnTextChanged(EventArgs.Empty); } protected virtual void OnTextChanged(EventArgs e) { if (TextChanged != null) TextChanged(this,e); } protected override void Render(HtmlTextWriter output) { output.Write(""); } } }