IPostbackEventHandler VS IPostbackDataHandler

1) A user who selects an item in a DropDownList is considered a postback, and for this reason DropDownList implements IPostbackDataHandler.

a) But why the user does not move (in calendar control) to another month, is also considered a postback of data? Thus, why does Calendar implement IPostbackEventHandler and not IPostbackDataHandler?


2)
a) I assume that controls that implement IPostbackEventHandler instead of IPostbackDataHandler will never receive postback data?


b) If the control implements IPostbackDataHandler, then the postback event control will be triggered every time its data is changed, even if this control did not cause a postback

But if the control implements IPostbackEventHandler, then only the time that monitors the postback event will be raised if that control also caused a postback?

+6
c # events postback
source share
2 answers
  • DropDownList vs Calendar Event Interfaces:
    • The selection in the drop-down list is considered data. You send the information in the drop-down list as data (in most cases).
    • Changing a selection in a calendar control is considered an event, but not an event that transfers data. It just fires an event so that the code knows to change the control state.
      The difference between the two is very subtle.
  • The documentation for IPostBackEventHandler and IPostBackDataHandler explain their purpose in the documentation, but they cannot make the difference understandable:
    • IPostBackEventHandler used to trigger events that are not dependent on data, but on user action. For example, a Calendar control may trigger an event when a date is clicked. This event depends on the user's actions, and not on the data entered by the user.
    • IPostBackDataHandler used to trigger events that depend on the data in the control. For example, a TextBox has an OnTextChanged event, which should only fire when text is changed in a TextBox .
+19
source share

To add, controls that implement IPostbackDataHandler do not rely on view state to store data through postbacks.

Edit: but all controls depend on the state of the view to maintain visibility

+3
source share

All Articles