<Action>
After a form submits successfully, the <Action> tag loads a .NET assembly from your site's /bin folder and runs its custom code. Use it as an escape hatch when none of the built-in action tags (<Email>, <SilentPost>, <AddUser>, etc.) cover your need.
Custom actions can read and modify the in-memory form values, so an <Action> early in the form's action list can transform data that later actions consume.
Action timing
Action tags only run when the form submits successfully — they run after the <SubmitCommand> writes to the database, so they cannot prevent the database write or alter what was written. They evaluate their tokens at that point, so [[FieldName]] tokens read the values the user submitted.
Example
<AddForm>
<SubmitCommand
CommandText="INSERT INTO Users(FirstName, LastName) VALUES(@FirstName, @LastName)" />
<Action Assembly="MyCompany.XMPActions" Namespace="MyCompany.XModPro.Actions.MyCustomAction" />
<table>
<tr>
<td><Label For="txtFirstName" Text="First Name" /></td>
<td><TextBox Id="txtFirstName" DataField="FirstName" DataType="String" /></td>
</tr>
<tr>
<td><Label For="txtLastName" Text="Last Name" /></td>
<td><TextBox Id="txtLastName" DataField="LastName" DataType="String" /></td>
</tr>
<tr>
<td colspan="2"><AddButton Text="Add" /> <CancelButton Text="Cancel" /></td>
</tr>
</table>
</AddForm>Properties
| Property | Values | Default | Description |
|---|---|---|---|
| Assembly * | string | Name of the DLL in /bin (without the .dll extension) | |
| Namespace * | string | Namespace + class name pointing to the action class within the DLL |
* Required property
Child Tags
| Tag | Required | Description |
|---|---|---|
<Property> | optional | Passes a name/value pair to the custom action's Properties collection |
<Property>
Adds a single name/value pair to the action's Properties list. The custom action class must expose a public Properties property (List(Of ActionProperty)) for these to be applied.
| Attribute | Values | Default | Description |
|---|---|---|---|
| Name * | string | Property name | |
| Value | string | token | Property value. Field tokens are evaluated when the action runs |
Property Details
Assembly: The file name of your compiled DLL in the site's
/bindirectory, without the.dllextension. For example, ifbin\MyCompany.XMPActions.dllis your DLL, setAssembly="MyCompany.XMPActions".Namespace: The full namespace plus class name pointing to your action class — XMP loads the type
{Assembly}.{Namespace}from the assembly. The way you set this depends on whether your project is VB.NET or C#:VB.NET
Visual Studio's VB.NET projects automatically set the project's
Root Namespaceto the same value as theAssemblyname. We recommend clearing theRoot Namespace(set it to empty), so XMP can prepend the assembly name itself.With a class file like this:
vbnetImports DotNetNuke.Entities.Modules Imports KnowBetter.XModPro.Common Imports KnowBetter.XModPro.Web.Controls.Form.Action Namespace MyActions Public Class SendNotification Inherits ActionBase Public Overrides Sub Execute(pmb As PortalModuleBase, ByRef xi As XItem) ' Code to send notification here End Sub End Class End NamespaceThe matching tag is:
html<Action Assembly="CustomXMPCode" Namespace="MyActions.SendNotification" />If you don't include a
Namespaceblock in the class file, drop the namespace from the tag:html<Action Assembly="CustomXMPCode" Namespace="SendNotification" />C#
Visual Studio's C# projects set the
Default Namespaceto the assembly name. Keep that default and omit it from the tag'sNamespace. With a class file like this:csharpnamespace CustomXMPCode.MyActions { using DotNetNuke.Entities.Modules; using KnowBetter.XModPro.Common; using KnowBetter.XModPro.Web.Controls.Form.Action; public class SendNotification : ActionBase { public override void Execute(PortalModuleBase pmb, ref XItem xi) { // code to send notification here } } }The matching tag is:
html<Action Assembly="CustomXMPCode" Namespace="MyActions.SendNotification" />
Building a custom action
Create a class library in Visual Studio.
Add references to
DotNetNuke.dllandKnowBetter.XModPro.Common.dll(andKnowBetter.XModPro.Web.Controls.dllif you inherit fromActionBase).Create a class that inherits from
KnowBetter.XModPro.Web.Controls.Form.Action.ActionBase.Override the
Executemethod:vbnetImports DotNetNuke.Entities.Modules Imports KnowBetter.XModPro.Common Imports KnowBetter.XModPro.Web.Controls.Form.Action Namespace MyActions Public Class MyAction Inherits ActionBase Public Overrides Sub Execute(pmb As PortalModuleBase, ByRef xi As XItem) ' pmb provides environmental data (PortalId, UserId, etc.). ' xi contains the form values that were just submitted. ' xi is passed by reference, so any values you change or add ' are visible to <Action>, <Email>, and <Redirect> tags ' that run after this one. End Sub End Class End NamespaceCompile and copy the DLL to your site's
/binfolder.Reference the action from your form using
<Action>.