/
SimpleCallbackExample.cs
71 lines (63 loc) · 2.83 KB
/
SimpleCallbackExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Layout;
using DevExpress.ExpressApp.Model.NodeGenerators;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Templates;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Web;
using DevExpress.ExpressApp.Web.Templates;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.Validation;
using XafCallBack.Module.BusinessObjects;
namespace XafCallBack.Module.Web.Controllers
{
// For more typical usage scenarios, be sure to check out https://documentation.devexpress.com/eXpressAppFramework/clsDevExpressExpressAppViewControllertopic.aspx.
public partial class SimpleCallbackExample : ViewController, IXafCallbackHandler
{
public SimpleCallbackExample()
{
InitializeComponent();
this.TargetObjectType = typeof(DomainObject1);
SimpleAction ExecuteScriptWithCallback = new SimpleAction(this, "ExecuteScriptWithCallback", PredefinedCategory.View);
ExecuteScriptWithCallback.Caption = "Execute script with callback to code behind";
ExecuteScriptWithCallback.Execute += ExecuteScriptWithCallback_Execute;
}
private void ExecuteScriptWithCallback_Execute(object sender, SimpleActionExecuteEventArgs e)
{
((WebWindow)this.Frame).RegisterStartupScript("ExecuteScriptFromAction", "RaiseXafCallback(globalCallbackControl, 'MyScript', 'Hello XAF!!! from java script', '', false);");
}
protected XafCallbackManager CallbackManager
{
get { return ((ICallbackManagerHolder)WebWindow.CurrentRequestPage).CallbackManager; }
}
protected override void OnActivated()
{
base.OnActivated();
// Perform various tasks depending on the target View.
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
//HACK you need to register the callbacks in this method "OnViewControlsCreated" otherwise the callback won't trigger
CallbackManager.RegisterHandler("MyScript", this);
}
protected override void OnDeactivated()
{
// Unsubscribe from previously subscribed events and release other references and resources.
base.OnDeactivated();
}
void IXafCallbackHandler.ProcessAction(string parameter)
{
CallbackManager.NeedEndResponse = false;
string Script = $"alert('the script was executed and the parameter value is {parameter}')";
((WebWindow)this.Frame).RegisterStartupScript("CallBack", Script, true);
}
}
}