问题描述
1)
用户选择 DropDownList 中的项目被认为是回发数据,因此,DropDownList 实现了IPostbackDataHandler 。
1)User selecting an item in DropDownList is considered to be postback data, and for that reason DropDownList implements IPostbackDataHandler.
a)但是为什么用户移动(在日历控件)到另一个月也被认为是回发数据?因此,为什么日历实现IPostbackEventHandler 而不是IPostbackDataHandler ?
a) But why isn’t user moving ( in Calendar control ) to another month also considered a postback data? Thus, why does Calendar implement IPostbackEventHandler and not IPostbackDataHandler?
2)
a)我认为实施 IPostbackEventHandler 而不是 IPostbackDataHandler 的控件从未收到回传数据?
2)
a) I assume that controls implementing IPostbackEventHandler instead of IPostbackDataHandler never receive postback data?
b)如果控件实现IPostbackDataHandler 那么控制的回发事件将在每次数据更改时触发,即使该控件没有引起回发
b) If control implements IPostbackDataHandler, then control’s postback event will be fired each time its data changed, even if that control didn’t caused a postback
但是如果控件实现IPostbackEventHandler 那么只有这个控件的回传事件才会被提升的时间是该控件是否也触发回发?
But if control implements IPostbackEventHandler, then only time that control’s postback event will be raised is if that control also triggered a postback?
推荐答案
- DropDownList vs Calendar事件接口:
- 下拉列表中的选择被视为数据。您将在下拉列表中将信息作为数据(大多数情况下)提交。
- 将日历控件上的选择更改为一个事件,而不是提交数据的事件。它只是触发事件,以便代码知道更改控件的状态。
这两者之间的区别是非常微妙的。
-
IPostBackEventHandler
用于触发不依赖于数据但不依赖用户操作的事件。例如,Calendar
控件可以在点击日期时触发事件。此事件取决于用户的操作,而不是用户输入的数据。 -
IPostBackDataHandler
用于触发依赖于控件中的数据。例如,一个TextBox
有一个OnTextChanged
事件,只有当TextBox
更改。
IPostBackEventHandler
is used for triggering events that are not dependent on data, but on a user's action. For example, theCalendar
control can trigger an event for when a date is clicked. This event is dependent on a user's actions, not the data the user entered.IPostBackDataHandler
is used for triggering events that are dependent on data in the control. For example, aTextBox
has anOnTextChanged
event, which should only be triggered if the text in theTextBox
changes.
这篇关于IPostbackEventHandler VS IPostbackDataHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!