views:

1559

answers:

2

hi


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?


thank you

+5  A: 
  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.
Dan Herbert
If I could, I would accept this answer in place of the guy that asked it and never looked back.
Dave Van den Eynde
+1  A: 

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

MOZILLA
+1 - Excellent point..
desigeek