Get Telerik object using javascript/jQuery

2 posts, 0 answers
  1. Antonio
    Antonio avatar
    2 posts
    Member since:
    Jul 2010

    Posted 10 Apr 2012 Link to this post

    In javascript, $find returns a reference to a Telerik object's exposed client API (e.g., set_enabled, set_autoPostBack, etc.)

    Right now, I use this script to get it by the suffix of the id:

    var $findByBaseId = function (baseId) {
            return $find($('[id$=' + baseId + ']').attr('id'));
    };

    Works ok, but seems a little roundabout.  Is there a built in Telerik function that does this?  It seems like I'm scanning the DOM twice.

    I'm avoiding the <%%> tags to allow the scripts to be moved to separate files.
  2. Antonio
    Antonio avatar
    2 posts
    Member since:
    Jul 2010

    Posted 10 Apr 2012 Link to this post

    Never mind.  A little more digging and I found Sys.Application._components which is a dictionary of controls.

    var $findByBaseId = function (baseId) {
        var re = new RegExp(baseId + '$');
        for (var key in Sys.Application._components) {
            if (re.test(key)) return Sys.Application._components[key];
        }
        return null;
    };

    I guess $find doesn't do a DOM scan; looks like Sys.Application.findComponent() just does a lookup.
Back to Top