我覺得是這樣工作的:因爲它是由它的文本狀態發射
TextBox控件實現IPostBackDataHandler代替IPostBackEventHandler。因此,如果任何變化postedValue發生被判定
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("<INPUT type= text name = "+this.UniqueID
+ " value = " + this.Text + " >");
}
}
}
它可能是ControlState,它跟蹤並保持控件的基本信息,但如果它是Control State,那麼爲什麼IPostBackDataHandler是由TextBox實現的? – Tarik 2009-10-19 04:21:09