Create a custom action in ASP. NET Atlas

Source: Internet
Author: User

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:

    1. SYS. invokemethodaction: Used to call a specified function.
    2. Set. setpropertyaction: Used to set a property value of an object.
    3. 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:

    1. Inherited fromSYS. ActionBase class.
    2. Define YourAction class. InAlertactionIn the example, we need to specifyMessageAttribute is used to save the content to be displayed to the user.
    3. 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.
    4. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.