Actions are specified in the control definition file and are executed after you drop a user control in a web form.
They are mainly intended to "teach" the programmer about how to use the user control by "creating" a usage sample.
If you drag the GxChart control to a web form, you will notice 4 different things:
- A &GxChartData variable is created
- A &GxChartSeries variable is created
- The &GxChartData variable is assigned to the control
- A code snippet is created
All the steps described above can be accomplished by using Actions.
The available actions are:
- VarDeclaration Allows defining a variable
- SetPropertyToControl Sets a control property
- CodeSnippet Adds a code snippet to the object where you are using the user control
For more information about Actions, see User Control definition file.
Actions are composed of a type and properties, and can be executed in a given order.
Let's see the case of the GxChart UC. You can analize the complete example (GxChart control) here
The example below declares a new variable. The VarDeclaration action has 2 properties:
- name: this is the variable name
- attCustomType: this is the variable data type
<Action>
<Order>0</Order>
<ActionProperties>
<Property>
<Key>
<string>Name</string>
</Key>
<Value>
<string>GxChartData</string>
</Value>
</Property>
<Property>
<Key>
<string>ATTCUSTOMTYPE</string>
</Key>
<Value>
<string>GxChart</string>
</Value>
</Property>
</ActionProperties>
<Data></Data>
<ActionType>VarDeclaration</ActionType></Action>
The action that follows will set the &GxChartData variable created in action 1 (explained above) to the Data property of the GxChartControl (Data is the internal name of the GxChart property seen in the property grid). So basically, when using the SetPropertyToControl action you have to define as many properties as variables you want to assign. The property key must be the name of the control property and value is the variable you want to assign.
<Action>
<Order>2</Order>
<ActionProperties>
<Property>
<Key>
<string>Data</string>
</Key>
<Value>
<string>&GxChartData</string>
</Value>
</Property>
</ActionProperties>
<Data></Data>
<ActionType>SetPropertyToControl</ActionType>
</Action>
The CodeSnippet action allows adding some code to the object where the UC is dropped. The code must be declared in the Data tag of the action as shown below.
<Action>
<Order>3</Order>
<ActionProperties/>
<Data>
// Sample code for GxChartControl
Sub 'GxChartSample'
&GxChartData.Categories.Add("2004")
&GxChartData.Categories.Add("2005")
&GxChartData.Categories.Add("2006")
&GxChartSerie.Name = "Sales"
&GxChartSerie.Values.Add(3045)
&GxChartSerie.Values.Add(4246)
&GxChartSerie.Values.Add(6537)
&GxChartData.Series.Add(&GxChartSerie)
EndSub
</Data>
<ActionType>CodeSnippet</ActionType>
</Action>