当文本框TextChanged事件被解雇?

编程入门 行业动态 更新时间:2024-10-23 19:19:06
本文介绍了当文本框TextChanged事件被解雇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题是:

正如我们所知道的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事件被解雇?

本文发布于:2023-11-10 00:46:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573906.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   事件   TextChanged

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!