1

I'm trying to add a button on a page that remove any personalization.

I use this code :

 protected void MyButton_Click(object sender, EventArgs e) {
        WebPartManager.Personalization.ResetPersonalizationState();
        // other cleanup methods
 }

However, this code is failling with this error:

The 'ResetPersonalizationState' method of 'WebPartPersonalization' cannot be called before initialization of the page is complete

What is the correct way to implement this behavior?

[Edit] Please note that I'm working on server side. Actually, I'm performing some other cleanup when clearing the personalizations.

I try to perform a postback after calling the MSOWebPartPage_RestorePageDefault but it seems that this method itself is performing a post, so my postback is ignored.

I used this code:

javascript:SP.SOD.executeFunc('browserScript', 'MSOWebPartPage_RestorePageDefault', function(){
    MSOWebPartPage_RestorePageDefault();
    __dopostback(...); // actually generated on the server side
})

But as I said, it does not works (the __dopostback is ignored as the MSOWebPartPage_RestorePageDefault itselft postback.

1 Answer 1

1

To reset the personalisation you simply need to call a JavaScript on that button.

javascript:SP.SOD.execute('browserScript', 'MSOWebPartPage_RestorePageDefault')

When the user clicks the button he will be asked to reset the personalisation. Once the user confirms this the personalisations are gone.

1
  • thanks for your suggestion. However, it's a bit more complicated (see my edit).
    – Steve B
    Feb 17, 2014 at 23:19

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.