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 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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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?

share|improve this answer
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 Aug 1 '12 at 6:39

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;
        }
    }
share|improve this answer
    
I think that ApplyChanges is invoked on apply button click too :) –  Alexander Jun 28 '12 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. –  Steve Lineberry Jun 28 '12 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 Jun 28 '12 at 13:43
    
You are correct in that is what he said Alexander. Sorry, I misread his question. –  Steve Lineberry Jun 28 '12 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 Aug 1 '12 at 6:43

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.