Question

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

Was it helpful?

Solution

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);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top