Here are some background infos for this question: Where to load data in the lifecycle of custom webpart

Having a webpart with different controls (buttons, dropdownlist etc.), I want to check, if a postback was made by a control of my custom webpart.

I want to check that in CreateChildControls, where I initially load the data for my webpart.

If the postback happens and it came from my webpart, I don't want to load the data in CreateChildControls, because that happens in the HandleClickEvents method (with different parameters delivered from the sender object).

BUT: if the postback came from another webpart, I have to load initial data in CreateChildControls, to show the initial state.

There is a way to check which control sent the postback with:


But that doesn't work for ImageButtons.

Is there a way which works for all kinds of controls?

1 Answer 1


Normally, you just include code in whatever _Click() handler you have that would be triggering the postback and let .Net handle routing it to the proper place. Is there some reason why this is not working for you?

[edit] from updated question

Normally, you do not load data in CreateChildControls as that is not the proper event for that. Use the _Load() event and simply check if the .IsPostBack is set. If it is not a postback, load your data via code. If it is a postback then your data is already loaded from the ViewState.

Data loaded into your controls is put into the Viewstate by default. This is serialized when the page is posted back so that your controls are repopulated with this data automatically each time rather than having to load/reload constantly.

  • edited my question, to make it more clear.
    – Tom Bola
    Commented Feb 13, 2012 at 18:17
  • edited my answer to match the updated question :)
    – Dave Wise
    Commented Feb 13, 2012 at 18:27
  • added a link to put in some background information. Based on that it is not about data in the controls e.g. Dropdown. It's about the data being rendered. The data will be filtered by text input field and so fetched again in HandleClickEvents.
    – Tom Bola
    Commented Feb 13, 2012 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.