Create a custom action in ASP.net atlas

Source: Internet
Author: User
Tags definition implement reference return
The Asp.net| creation action is a class of components that inherit from the Sys.action base class in ASP.net atlas to implement a class of event-handling capabilities that are raised by an event. The action is similar to the function of the event handler, but it is a generalized event-handling component that describes some common, common event-handling methods, such as invoking a method, setting a property of an object, triggering a postback, and so on.





we all know that, so far, the best reference manual for Atlas is its source code. We can find the following three kinds of built-in action for Atlas from the source code, all of which inherit from the Sys.action base class:





sys.invokemethodaction: Used to invoke a specified function.





set.setpropertyaction: A property value that is used to set an object.





Sys.WebForms.PostBackAction: Used to raise a postback.





in actual projects, it is often not enough to use only the three built-in action, and we usually need to define some of the action that is commonly used in the project. Fortunately, creating a custom action will be a very simple thing to do in Atlas's complete architecture. Let's familiarize ourselves with the method of customizing the action with a simple alertaction example. When a specified event is raised, Alertaction is displayed to the user with a JavaScript prompt dialog box containing the specified text.





Typically, creating a custom action has the following four steps:





inherits from the Sys.action base class.





defines the properties of your action class. In the alertaction example, we need to specify a message property to hold the content that will be displayed to the user.





Implement the Performaction () method to perform the custom actions you want. This method will be invoked automatically by the action base class. In our example, we simply use the built-in alert () function in JavaScript to pop up the dialog box and display the contents of the message property.





for your custom action to add the associated type description in the GetDescriptor () method.





Below is the alertaction JavaScript code. The above four steps are marked in the code as comments. Save the following code as alertaction.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 () {


var td = Sys.AlertAction.callBaseMethod (this, ' getdescriptor ');





td.addproperty (' message ', String);


return TD;


}





//Step 3


This.performaction = 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 alertaction on the page. The only button that needs to be added to the page is to trigger our alertaction. The following is the HTML definition in the ASPX file. Don't forget to add a reference to the Alertaction.js file in ScriptManager.





<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 is the Atlas scripting definition, which is simple enough to repeat 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>


the results of the operation in the browser:








The above sample programs can be downloaded here: Http://www.cnblogs.com/Files/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.