1

I have a webpart with several properties that are part of a custom ToolPart. When i set the properties i would like the webpart to reflect the property changes while still editing after having clicked Apply/Ok but the page is still in Edit mode (i'm guessing in the ApplyChanges of my custom tool part). Any ideas?

TIA

2
  • After you make the changes , click on OK instead of Apply and close the edit mode page. Now save the page and browse back again and let me know the changes are getting reflected or not.
    – ArkoD
    May 31, 2012 at 17:25
  • 1
    That works....i was wondering, however, if there was a way to re-render the webpart with the changed properties while still in edit mode after hitting Apply. I was thinking that there might be a way in the ApplyChanges method
    – MikeC
    May 31, 2012 at 17:35

1 Answer 1

2

This purely depends on where in the life cycle of the Web Part you use the properties.

If you use the values early before the "ToolPane" gets the clicked event for Apply/OK which causes your ToolParts ApplyChanges to fire and change the properties, well then the changes wont show up until next pageload.

If you use the values late (after the clicked event) then the change will show up "immedately".

In my advanced web part below changes to TestCCC will not show until next pageload because I call EnsureChildControls in PageLoad which the adds the LiteralControl before the clicked event. Changes to TestRC which is will show immediately because it's rendered out late.

public class TestEditWP : WebPart
{
    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    public string TestCCC { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    public string TestRC { get; set; }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        EnsureChildControls();
    }
    protected override void CreateChildControls()
    {
        Controls.Add(new LiteralControl(TestCCC));
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
        base.RenderContents(writer);
        writer.Write("{0}", TestRC);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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