2

I have implemented a webpart with custom properties in an editor part. If I click apply or ok, the values are successfully updated (code in OnPreRender). The problem is now that if I click apply and then cancel, the changed values are saved and not discarded. I could not find a reason for that. Does anybody know a solution?

2 Answers 2

0

This is by design and not an error.

  1. Toolpart renders
  2. You update some properties in browser (A)
  3. You click apply and postback data
  4. ApplyChanges event saves data
  5. Toolpart renders with new data
  6. You (perhaps) update some values (B)
  7. You click Cancel
  8. Postback but does not update properties (ApplyChanges not fired)

Last data saved was (A) and thats what you've got - it cancelled any updates directly (B) before cancel.

Sure you could change this in your toolpart with some complex scheme but then your toolpart will work differently than everything else in SharePoint so is likely to be even more confusing.

Is this a real problem for you?

1
  • 1
    thx for your help ... I thought that the Apply button is just for "previewing" the webpart, but if it's the same in every other webpart, it's no problem for me!
    – Mel
    Commented Aug 1, 2012 at 6:39
0

Yea, i don't think onprerender is the right event to do this. It should be the applychanges override in the editorpart.

    public override bool ApplyChanges()
    {
        // Apply property values here.
        UserWebPart wp1 = (UserWebPart)this.WebPartToEdit;
        try
        {
            wp1.UserID = _p.CommaSeparatedAccounts;
            return true;
        }
        catch
        {
            return false;
        }
    }
5
  • I think that ApplyChanges is invoked on apply button click too :)
    – Alexander
    Commented Jun 28, 2012 at 13:12
  • Right, but he was saying that when he clicks cancel it saves as well, which shouldn't be the case with applychanges. Commented Jun 28, 2012 at 13:33
  • 1
    The issue is The problem is now that if I click apply and then cancel. I think that it is a default behavior. It's looks like you write a document, press save button and then continue writing. But you are right he should use ApplyChanges.
    – Alexander
    Commented Jun 28, 2012 at 13:43
  • You are correct in that is what he said Alexander. Sorry, I misread his question. Commented Jun 28, 2012 at 13:55
  • I already use the ApplyChanges method ... I just use the OnPreRender for updating my controls (like described in the following entry: sharepoint.stackexchange.com/questions/27526/…)
    – Mel
    Commented Aug 1, 2012 at 6:43

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.