0
votes

hi i am creating a webpart. i have a custom toolpart for my webpart. there i'll type some text. when i click save it will print in sharepointpage. when an user click cancel in webpart's toolpart i need to ask confirmation dialog and if the user selects "OK" i need to run some server side code. is it possible. Please help me on that.

2

2 Answers

2
votes

In your toolpart register an onsubmit event handler (this will be called on OK/Apply/Cancel or if you do anything else that causes a postback)

    protected override void OnPreRender(EventArgs e)
    {
        // Don't run if in SharePoint Designer
        if (ParentToolPane.InCustomToolPane)
            return;

        // Connect to the form Submit event RenderToolPart event is too late,            
        // Putting this in OnLoad event causes javascript error webpart may
        // be loaded for ApplyChanges but not rendered - leading to javascript error
        this.Page.RegisterOnSubmitStatement("submit", "yourCustom_onSubmit();");
        base.OnLoad(e);
    }

Also be sure to have a javascript function yourCustom_onSubmit on your page - putting up a confirmation message and cancelling submit is up to you.

0
votes

Yes you can. It's like asp.net, so you can insert a Javascript, like the sample we found at this site.