views:

555

answers:

1

So I've run into a snag, apparently the get_events method is only "included" with the ExtenderControl class.

What I need to do:

Be able to call the get_events Javascript method using a ScriptControl since using an ExtenderControl isn't really possible at this point.

I am hoping there is an easy way to have the scriptControl's javascript object inherit from something (If that's even possible).

A: 

Turns out the get_events method is really simple to create. You just need a field to hold a dictionary, a couple lines of code, and something to call the event if needed:

getEvents: function() 
{
    if (this._events == null) 
    {
        this._events = new Sys.EventHandlerList();
    }

    return this._events;
},

And now for access:

onItemSelected: function(args)
{
   this.raiseEvent('userItemSelected', args);
},

raiseEvent: function(eventName, eventArgs)
{
    var handler = this.getEvents().getHandler(eventName);
    if(handler)
    {
        handler(this._autoComplete, eventArgs);
    }

},

Basically events is just a dictionary that holds the name of the event and the reference to the method to call. Once you have the method (handler), it's just a matter of calling it.

Programmin Tool