Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPostbackEventHandler VS IPostbackDataHandler

1) User selecting an item in DropDownList is considered to be postback data, and for that reason DropDownList implements 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) I assume that controls implementing IPostbackEventHandler instead of IPostbackDataHandler never receive postback data?


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

But if control implements IPostbackEventHandler, then only time that control’s postback event will be raised is if that control also triggered a postback?

like image 599
PrgGnt Avatar asked May 27 '09 23:05

PrgGnt


2 Answers

  1. DropDownList vs Calendar event interfaces:
    • The selection in the drop down list is considered data. You would submit the information in the drop down list as data (in most cases).
    • Changing the selection on the Calendar control is considered an event, but not an event that submits data. It just triggers an event so that the code knows to change the control's state.
      The difference between these two is very subtle.
  2. The documentation for IPostBackEventHandler and IPostBackDataHandler explain their purpose in the documentation, but they fail to make the distinction clear:
    • IPostBackEventHandler is used for triggering events that are not dependent on data, but on a user's action. For example, the Calendar 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, a TextBox has an OnTextChanged event, which should only be triggered if the text in the TextBox changes.
like image 67
Dan Herbert Avatar answered Sep 17 '22 18:09

Dan Herbert


To add, controls which implement IPostbackDataHandler does not rely on the view state for retaining data across postbacks.

Edit: But all controls depend on view state to retain visibility

like image 41
MOZILLA Avatar answered Sep 18 '22 18:09

MOZILLA