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
This is by design and not an error.
- Toolpart renders
- You update some properties in browser (A)
- You click apply and postback data
- ApplyChanges event saves data
- Toolpart renders with new data
- You (perhaps) update some values (B)
- You click Cancel
- 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?
-
1thx 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!– MelCommented Aug 1, 2012 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;
}
}
-
I think that ApplyChanges is invoked on apply button click too :) 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
-
1The 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. 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/…)– MelCommented Aug 1, 2012 at 6:43