1 out of 1 rated this helpful - Rate this topic

How To: Create a Control Imperatively with JavaScript

The ASP.NET Ajax Library enables you to add controls to a page dynamically by using JavaScript.

The standard way to create controls programmatically with the ASP.NET Ajax Library is by calling the create method of Sys.Component. The create method is also available as a shorthand JavaScript global method named '$create'. The create method takes five parameters that are described in http://www.asp.net/ajaxlibrary/Reference.Sys-Component-create-Method.ashx. All but the first parameter are optional.

The following example shows how to create a Display Name Control for the signed in user in the DOM element with ID 'display-name'. It uses the Messenger Web Toolkit loader onReady function to ensure that all required script features are loaded.

    Microsoft.Live.Core.Loader.onReady(function() {
        $create(Microsoft.Live.UI.Messenger.DisplayNameControl,
            { cid: '$user' },
            {},
            {},        
            $get('display-name')
            );
        });
Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.