Showing posts with label associated. Show all posts
Showing posts with label associated. Show all posts

Wednesday, March 28, 2012

Accessing control extender behaviors in javascript

Hi there,

I'm using the AJAX 1.0 Beta 2 extensions and the AjaxControlToolkit. I'm finding it extremely hard to access the behaviors associated with a given control. (I'd like to hook into the expandComplete event of an CollapsiblePanel).

I've tried using the following:

var cp = $get('IdOfMyCollapsiblePanel');
cp.get_behaviors()[0].add_expandComplete(MyHandlerFunction);

This results in an error with the get_behaviors() call.

Can anyone post an example of how to hook up a javascript method to an extenders event? (client-side)

I'd really appreciate it!

Jeremy

And here I go replying to myself...

I found the source of my problem. I was trying to set up the event handling in the pageLoaded event that is raised by the PageRequestManager, but the behaviors are not yet loaded at this time. Instead I hooked the Sys.Application.load event and everything works!

Jeremy

Monday, March 26, 2012

Access class from inline frame

I have a composite control with associated javascript. The javascript uses registerClass to register a class. What I'd like to be able to do is access a method in this class from outwith my control, from another frame to be specific. Normally I'd simply do parent.class.method but when I try that I get a "not a function" error. When I try alerting the class I get the javascript code for it and not the instance.

So how do I get the instance of the class registered with registerClass from within another frame, if it is at all possible.

Thanks.

Hi

Would you please provide us with your code,so we can reproduce this issue quicklier?

Thanks


Thanks for the reply.

This is the javascript code for the control, I have snipped some of the functions to cut the length.

Type.registerNamespace('number45');

number45.editor = function(element) {

number45.editor.initializeBase(this, [element]);

this.type = 'editor';
this.editor_obj_id = '';
this.toolbar_id = '';
this.colors = '';

this.popups = new Array();
this.buttons = new Array();
this.popupshowing = '';
};

number45.editor.prototype = {

initialize: function()
{
number45.editor.callBaseMethod(this, 'initialize');

this.editor_obj = document.getElementById(this.editor_obj_id);

var documentClick = Function.createDelegate(this, this.close);
$addHandler(document, 'click', documentClick);
},

dispose : function() {
$clearHandlers(this.get_element());

number45.editor.callBaseMethod(this, 'dispose');
},

get_editor_obj_id: function()
{
return this.editor_obj_id;
},

set_editor_obj_id: function(value)
{
this.editor_obj_id = value;
},

insertText : function(newtext) {
this.checkFocus();
if (document.selection)
document.selection.createRange().text = newtext;
else {
if (typeof(this.editor_obj.selectionStart) != 'undefined') {
this.editor_obj.value = this.editor_obj.value.substr(0, this.editor_obj.selectionStart) + newtext + this.editor_obj.value.substr(this.editor_obj.selectionEnd, this.editor_obj.value.length);
} else {
this.editor_obj.value += newtext;
}
}
},

insertAttachment : function(attachment) {
var start_tag = '[image]';
var end_tag = '[/image]'

this.insertText( start_tag + attachment + end_tag );
},

}

number45.editor.registerClass('number45.editor', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

function stop_bubble(obj) {
if (!obj) {
window.event.cancelBubble=true;
return window.event;
} else {
obj.stopPropagation();
return obj;
}
};

It is the functioninsertAttachment I want to call from the inline frame. I have tried usingparent.number45.editor.insertAttachment('x'), this is what causes the 'not a function' error. When I try alertingparent.number45.editor I get the body of thefunction(element) shown.