This is a post in my blog series Introduction to Chameleon...
Action controls define a single function or behavior that can be invoked by other Chameleon controls when configurable events occur.
Action controls are generally used when a Chameleon form control completes a processing event, such as the successful submission of a blog contact form. For example,
<CSBlog:ContactForm runat="server" SubjectTextBoxId="Subject" NameTextBoxId="Name" EmailTextBoxId="Email" MessageTextBoxId="Body" SubmitButtonId="Submit">
<SuccessActions>
<CSControl:SetVisibilityAction runat="server" ControlIdsToShow="SuccessMessage" />
</SuccessActions>
<FormTemplate>
<div><CSControl:FormLabel LabelForId="Name" runat="server" ResourceName="Weblog_ContactForm_Name" /></div>
<div><asp:TextBox id="Name" runat="server" /></div>
<div><CSControl:FormLabel LabelForId="Email" runat="server" ResourceName="Weblog_ContactForm_Email" /></div>
<div><asp:TextBox id="Email" runat="server" /></div>
<div><CSControl:FormLabel LabelForId="Subject" runat="server" ResourceName="Weblog_ContactForm_Subject" /></div>
<div><asp:TextBox id="Subject" runat="server" /></div>
<div><CSControl:FormLabel LabelForId="Body" runat="server" ResourceName="Weblog_ContactForm_Body" /></div>
<div><asp:TextBox id="Body" runat="server" TextMode="MultiLine" /></div>
<div>
<asp:Button id="Submit" runat="server" Text="Send" />
<CSControl:ResourceControl runat="Server" id="SuccessMessage" ResourceName="Weblog_ContactForm_Sent" Visible="false" />
</div>
</FormTemplate>
</CSBlog:ContactForm>
uses the <CSControl:SetVisibilityAction /> action control to identify that, when the <CSBlog:ContactForm /> is successfully submitted, the control with ID "SuccessMessage" should have it's Visibility property set to true.
There are many action controls defined within Community Server 2007 and new action controls can be easily defined (all Action controls inherit from ActionBase). Existing action controls include:
- ExecuteScriptAction (<CSControl:ExecuteScriptAction />)
ExecuteScriptAction will execute the javascript specified by the Script property.
- GoToCurrentContentAction (<CSControl:GoToCurrentContentAction />)
GoToCurrentContentAction will navigate to view the current content object, if a Content object exists in the current context.
- GoToCurrentPostAction (<CSControl:GoToCurrentPostAction />)
GoToCurrentPostAction will navigate to view the current post if a Post exists in the current context.
- GoToModifiedUrlAction (<CSControl:GoToModifiedUrlAction />)
GoToModifiedUrlAction will apply the specified query string (QueryStringModification property) and target (TargetLocationModification property) modifications to the current URL and navigate to the resulting modified URL.
- GoToReferralUrlAction (<CSControl:GoToReferralUrlAction />)
GoToReferralUrlAction will navigate to the referral URL as specified on the query string if a referral URL exists.
- GoToSiteUrlAction (<CSControl:GoToSiteUrlAction />)
GoToSiteUrlAction will navigate to the specified URL from the SiteUrls.config file as defined by the UrlName.
- SetVisibilityAction (<CSControl:SetVisibilityAction />)
SetVisibilityAction will set the controls identified by its ControlIdsToShow property to visible (Visible = true) and set the controls identified by its ControlIdsToHide property to hidden (Visible = false). Both lists are comma-separated.
- CustomAction (<CSControl:CustomAction />)
CustomAction adds support for code-based actions by exposing an event, CustomEvent, which can be used to implement inline code. The CustomEvent is passed a reference to the parent control executing the event as well as the parent control's parameter (which is control-specific).
For example,
<script runat="server" language="C#">
protected void MyCustomEventHandler(System.Web.UI.Control sender, object parameter)
{
// custom code here
}
</script>
<CSControl:CustomAction runat="server" CustomEvent="MyCustomEventHandler" />
would execute the custom code within the MyCustomEventHandler method defined on the page.
- Actions (<CSControl:Actions />)
Actions executes a set of sub-actions. The "SuccessActions" inner-property on the <CSBlog:ContactForm /> example above is an Actions control.
Note that more than one action control can be used. Actions are executed in the order they are defined so for example,
<SuccessActions>
<CSControl:GoToReferralUrlAction runat="server" />
<CSControl:SetVisibilityAction runat="server" ControlIdsToShow="SuccessMessage" />
</SuccessActions>
would first attempt to navigate to the referral URL as specified on the querystring. If no referral URL is defined, the "SuccessMessage" control will be made visible.
Action simply controls provide a mechanism that allows theme developers to customize the behavior of forms. Theme developers can now implement custom navigation and notification behaviors specific to the needs of their themes.
If you have any questions regarding Chameleon, please send them to me via my contact form or add a comment. I will answer all the questions in the final post in this series.
In my next post in this series, I will discuss Utility controls.