当文本框TextChanged事件被解雇? [英] When TextBox TextChanged event is fired?
问题描述
我的问题是:
正如我们所知道的ViewState是不负责存储和恢复的TextBox,CheckBox和控制等价值观。发生这通过的LoadPostData()方法来实现IPostBackDataHandler界面控件完成的。
As we know ViewState is not responsible for storing and restoring TextBox,CheckBox and such controls Values. This is done by LoadPostData() method to controls that implement IPostBackDataHandler interface.
和我们也知道加载阶段之后,RaisePostBackEvent阶段,并提高相应的事件,例如按钮点击或者文本在TextBox改变,它的TextChanged事件将被解雇。
And we also know after Load stage,RaisePostBackEvent stage occurs and raise corresponding events such Button Click or if Text changed in a TextBox, its TextChanged event will be fired.
那么,如何系统的跟踪,如果ViewState是不负责和机制实际上触发文本框中的文本改变框TextChanged事件?
So how does system track the text changed if ViewState is not responsible for that and which mechanism actually fires TextBox TextChanged event ?
我其实在这一点上混淆。
I am actually confused at this point.
在此先感谢。
推荐答案
我觉得是这样工作的:
文本框因为它是由它的文本状态发射控件实现IPostBackDataHandler,而不是IPostBackEventHandler。因此,如果任何变化postedValue发生被确定
TextBox control implements IPostBackDataHandler instead of IPostBackEventHandler because it's fired by its text state. So if any changes happened in postedValue which is determined
if (presentValue == null || !presentValue.Equals(postedValue)) {
Text = postedValue;
return true;
}
部分则返回true,并继续执行所以最后框TextChanged解雇。 。PFF混乱,但看起来很容易寿
portion then it returns true and keep executing so finally TextChanged fired. Pff confusing but looks easy tho.
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 + " >");
}
}
}
这篇关于当文本框TextChanged事件被解雇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!