Developer Forum »
Handling event of editing content in edit panel
36 posts

Hi devs!

When I click an existing content to edit it - is there a way I can hook into the event of opening the content editor? I'd like to synchronize some data from external service.

Regards,

Andrzej

181 posts

Hi!

There is no specific event to do this, but there are ways around it. But contacting an external service synchronously each time you open it in edit is not a very good approach. Given the latency of an external request and the response time of that service will compromise the user experience in Webnodes. 

I would suggest that you start a workflow when you open a node in Webnodes. The workflow checks with the external service, and if the data has changed, it can ask the user if it should update the data (this will mean a refresh of the page).

But in order to detect if a node is opened in edit, override the GetPropertyWebControlType method. Make sure you only do something for one of the properties. This method will be called once for each property.

 public override Type GetPropertyWebControlType(PropertyControlMode controlMode, PropertyInstance property) {
        return base.GetPropertyWebControlType(controlMode, property);
    }
36 posts

Thanks Vidar. I understand the problem which could appear when I fetch data from external service. What about this scenario then (still want to extend the native user editor):

- I have a classthat inhertis from user e.g. Employee

- in edit panel in "Employee" tab Id like to add a button, that I could handle in C# code (that would for instnace send a special email to that user)

Is this possible?

 

Cheers,

Andrzej

181 posts

There is a CommandProperty that is rendered as a button in the edit interface. 

The CommandProperty has two relevant settings:

"Method name" and "Use Command Workflow"

Method name is the name of the method on the partial class that should invoke when the button is clicked.

"Use Command workflow" determines if the method should be run as part of the request in edit, or if it should be started from a workflow. If started from workflow, it runs in a separate thread, so it will run in the background. 

The drawback is that it can't access the web context if you need to access information from the web context.

For the ultimate in flexibility, choose to run it in web context, but start a workflow from within the method. Set properties on the workflow object to give the workflow the information it needs from the web context.

Let me know if you want more detailed instructions.

36 posts

That sounds like a very nice solution with the command property. Thanks a lot!

1