Http://dflying.dflying.net/1/archive/122_build_your_own_actions_in_aspnet_atlas.html
ActionYesASP. NET AtlasInherited fromSYS. ActionA Class component of the base class, which is used to implement the event processing function triggered by an event.ActionSimilar to the functions of event processing functions, but it is a type of Generalized Event processing component used to describe some common and common event processing methods, such as calling a method, sets a property of an object and triggersPostBack.
We all know that, so far,AtlasThe best reference manual is itsSource code. We canCodeFind the following threeAtlasBuilt-inActionThey all inherit fromSYS. ActionBase class:
- SYS. invokemethodaction: Used to call a specified function.
- Set. setpropertyaction: Used to set a property value of an object.
- SYS. webforms. postbackaction: Used to triggerPostBack.
In actual projects, only the three built-inActionIt is often not enough. We usually need to define some commonly used projects by ourselves.Action. FortunatelyAtlasCreate customActionIt will be very simple. Next let's use a simpleAlertactionExamples to familiarize yourself with CustomizationAction. When a specified event is triggered,AlertactionWill be displayed to the userJavascriptThe prompt dialog box contains the specified text.
Generally, create a customActionThere are four steps:
- Inherited fromSYS. ActionBase class.
- Define YourAction class. InAlertactionIn the example, we need to specifyMessageAttribute is used to save the content to be displayed to the user.
- ImplementationInvalid maction ()To perform the custom operations you need. This method will beActionThe base class is automatically called. In our example, it is simple to use.JavascriptBuilt-inAlert ()Function to pop up the dialog box, and displayMessageAttribute.
- For your customActionInGetdescriptor ()Method.
Below isAlertactionOfJavascriptCode. The above four steps are marked with comments in the code. Save the following codeAlertaction. js.
SYS. alertaction = Function () {
SYS. alertaction. initializebase ( This );
// Step 2
VaR _ Message;
This . Get_message = Function () {
Return_ Message;
}
This . Set_message = Function (Value) {
_ Message=Value;
}
// Step 4
This . Getdescriptor = Function () {
VaRTD=SYS. alertaction. callbasemethod (This, 'Getscriptor ');
TD. addproperty ('message', string );
ReturnTD;
}
// Step 3
This . Category maction = Function () {
Alert (_ message );
Return Null;
}
}
// Step 1
SYS. alertaction. registersealedclass ('sys. alertaction', SYS. action );
SYS. typedescriptor. addtype ('script', 'alertaction', SYS. alertaction );
Let's test this on the page.Alertaction. Here, you must add only oneButtonTo trigger ourAlertaction. Below isAspxFileHtmlDefinition. Do not forgetScriptmanagerAddAlertaction. jsFile reference.
< Atlas: scriptmanager Enablepartialrendering = "True" ID = "Scriptmanager1" Runat = "Server" >
< Scripts >
<Atlas: scriptreference path="Alertaction. js" />
</ Scripts >
</ Atlas: scriptmanager >
< Div >
< Input ID = "Mybutton" Type = "Button" Value = "Click me! " />
</ Div >
Below isAtlasThe script definition is very simple and will not be repeated here.
< Script Type = "Text/XML-script" >
< Page Xmlns: script = "Http://schemas.microsoft.com/xml-script/2005" >
< Components >
< Button ID = "Mybutton" >
< Click >
< Alertaction Message = "Button clicked! " />
</ Click >
</ Button >
</ Components >
</ Page >
</ Script >
Result in the browser:
ExampleProgramDownload here: http://files.cnblogs.com/dflying/AtlasActionDemo.zip