Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

Edit

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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).

share|improve this answer
    
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 '11 at 1:28
    
just one thing: that's a sandbox solution, so ToolPart should leave place to EditorPart. –  superjos Oct 21 '11 at 22:45
    
Good spot, yep. –  James Love Oct 21 '11 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:

ASP.NET PAGE / CONTROL LIFECYCLE

share|improve this answer
    
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 '11 at 1:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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