I have a test SP page hosting a Sandbox WebPart, code only. The WebPart in turn contains a GridView.

I'd like to refresh the WebPart (actually, to fire the GridView-ObjectContainerDataSource selection process) after the user has done with modifying the WebPart, i.e after s/he has clicked OK in the (standard, non custom) right editor pane.

I've looked and tried with:

I've searched on the web, but apparently everyone explains how to set the displaymode, and no one how to detect its changes :).

Any help? TA


I played a little bit with WebPart.OnEditModeChanged and ViewState. The problem is still due to OnEditModeChanged being called only on the first transition Display->Edit, then never again. This makes it impossible (I think) to track state when user does Display-Edit-Apply-Ok for example.

2 Answers 2


You could add a class which inherits from ToolPart, and override the ApplyChanges() class to do whatever extra you need, which is fired when OK is clicked and before the page is prepped to be reloaded.

You'll then need to add that custom ToolPart class the other ToolParts added to the web part (done by overriding GetToolParts() in your web part class).

  • Thanks for your answer James (kind of famous here). I'll wait some more to see if there's any other feedback. In the end I might go down this path anyway, as I'll probably want to customize the editing experience (big word :).
    – superjos
    Oct 20, 2011 at 1:28
  • just one thing: that's a sandbox solution, so ToolPart should leave place to EditorPart.
    – superjos
    Oct 21, 2011 at 22:45
  • Good spot, yep.
    – James Love
    Oct 21, 2011 at 23:00

Have you tried to override the OnPreRender method and rebinding the GridView there? The OnPreRender method is one of the last methods to be called in the aspx page / control lifecycle.

And perhaps checking for IsPostBack to fire only on postbacks (i.e. OK click in editor).

P.S. this is a very commonly asked question (not only with regards to controls / webparts in SharePoint), but ASP.NET in general. The image below illustrates how the flow of methods is in regular (non MVC) ASP.NET:


  • thanks for your answer. Yes I am aware of the ASP.NET flow of page/control event (I've seen that one from MSDN too :). But I'd prefer not to rebind on each post-back (think about row selection). I'd like to figure out if a postback is due to the Ok or Apply button pressed on the editor pane.
    – superjos
    Oct 20, 2011 at 1:25

Your Answer

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

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