Share via


ToolPart.ApplyChanges method

Called when the user clicks the OK or the Apply button in the tool pane.

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Overridable Sub ApplyChanges
'Usage
Dim instance As ToolPart

instance.ApplyChanges()
public virtual void ApplyChanges()

Examples

The following example demonstrates the use of the ApplyChanges method to apply the new value (entered by the user in a textbox in the tool pane) to the intended Web Part.

public class SimpleToolPart : ToolPart
    {
        TextBox tb;
        bool changed=false;
        WebPart WebPartReference;

        protected override void CreateChildControls()
        {
            WebPartReference = (WebPart)ParentToolPane.SelectedWebPart;

            tb=new TextBox();
            tb.Text = WebPartReference.Title;
            tb.TextChanged+=new EventHandler(tbChanged);
            Controls.Add(tb);
        }
        protected override void RenderToolPart(HtmlTextWriter w)
        {
            this.RenderChildren(w);
        }
        private void tbChanged(object sender, System.EventArgs e)
        {
            changed=true;
        }
        public override void ApplyChanges()
        {            
            if(changed)
                WebPartReference.Title=tb.Text;
        }
        public override void SyncChanges()
        {
            tb.Text=WebPartReference.Title;
        }
    }
Public Class SimpleToolPart
        Inherits ToolPart
                Private tb As TextBox
                Private changed As Boolean=False
                Private WebPartReference As WebPart

                Protected Overrides Sub CreateChildControls()
                        WebPartReference = CType(ParentToolPane.SelectedWebPart, WebPart)

                        tb = New TextBox()
                        tb.Text = WebPartReference.Title
                        AddHandler tb.TextChanged, AddressOf tbChanged
                        Controls.Add(tb)
                End Sub
                Protected Overrides Sub RenderToolPart(ByVal w As HtmlTextWriter)
                        Me.RenderChildren(w)
                End Sub
                Private Sub tbChanged(ByVal sender As Object, ByVal e As System.EventArgs)
                        changed=True
                End Sub
                Public Overrides Sub ApplyChanges()
                        If changed Then
                                WebPartReference.Title=tb.Text
                        End If
                End Sub
                Public Overrides Sub SyncChanges()
                        tb.Text=WebPartReference.Title
                End Sub
End Class

See also

Reference

ToolPart class

ToolPart members

Microsoft.SharePoint.WebPartPages namespace