Menu:

Recent Entries

Categories

Archives

Links

Blogs
- Dflying's Night
- David's Untitled Life
- Dflying's Blog in Chinese

This blog is hosted by DreamHost!

Syndicate

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Build Your Own Actions in ASP.NET Atlas

Dflying | 13 April, 2006 03:09

Components derived from the Action class in Atlas are used to specify the code to execute in response to events, which is similar to the event handlers. Action components enable you to declaratively bind actions to client events for common tasks such as calling methods, setting properties, and triggering PostBacks.

The best reference of Atlas is the source code you know, and we can find there are three kinds of Atlas build-in Actions, which inherit from Sys.Action base class:

  1. Sys.InvokeMethodAction: Defines an action that calls a method.
  2. Set.SetPropertyAction: Defines an action that sets an object property to a specified value.
  3. Sys.WebForms.PostBackAction: Defines an action that performs a PostBack.

Sometimes you may need to make your own Actions to perform a specified task. Now let's go through an example, AlertAction, which is used to alert a message when an event got fired, to see how to build your own Atlas Actions.

Generally, there are four steps to build a custom Action:

  1. Inherit from Sys.Action base class.
  2. Define the properties of you custom Action. In this AlertAction demo, we defined a message property to specify the alert content.
  3. Implement method performAction() to perform your Action. Here it is very simple for we just need to call the JavaScript build-in function alert().
  4. Add descriptions in the getDescriptor() method.

Here's the code for AlertAction. The four steps above are marked inline. Save it 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);

Ok, let's test the AlertAction in a page. What we need on the page is just a button for invoking the Action.

Here is the HTML definition in ASPX. Do not forget to add a reference to our AlertAction.js 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>

And here is the Atlas script. Really simple one.

<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>

Runs in browser:

Demo source code available here: AtlasActionDemo.zip

Posted in Atlas. Comment: (2). Trackbacks:(328). Permalink
«Next post | Previous post»

Referers

Comments

  1. 1. Anu  |  08/10,2006 at 21:20

    Hi,

    I've a List View Control that gets its data from a webservice. In each row I want to have an Edit hyperlink which calls a javacsript function which requires all the values in that row as parameters. Can anyone please tell me how to bind the values in each row as parameters to the javscript function ?

    So I want I essentially want to do is , have a Sys.UI.HyperLink control call a javascript function with parameters when clicked on it. Kindly tell me how to specify parameters for the HyperLink control.

    Thanks in advance,
    Anu

  2. 2. uxlhohde  |  07/15,2008 at 12:29

    [URL=http://uiczxmek.com]uvutuhul[/URL] cgmgeehn http://tyvtfzzm.com ychsdcmq lytdqxyj rybvfdve

Leave a Reply

Auth Image