Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Wednesday, March 28, 2012

Accessing inherited behavior properties

Hello,

I've created a new extender who's behavior class in the javascript file inherits from an existing control (in this case the cascading drop down) and registered it like so:

CustomCascadingDropDown.CustomCascadingDropDownBehavior.registerClass(
'CustomCascadingDropDown.CustomCascadingDropDownBehavior', AjaxControlToolkit.CascadingDropDownBehavior
);

I'm listening for the selectedValue property change event to occur so that I can access the resulting value and operate on it but when I try to access it from my inherited behavior class as this._selectedValue I get a null value. If I try using the callBaseMethod method to access the property accessor I get a different exception. How do I access inherited properties?

Also, what is the correct procedure for attaching to property changed events? I assumed from other posts that is by using this.add_propertyChanged(handler) but is this correct? How does this attach itself to a specific property or does it just enumerate through all properties that have been changed?

Thanks in advance.

Hi,

can I see the code that you're using to handle the event?


Sure thing... thanks for the help by the way.

The code below is just a test. I just want to see if I can access the inherited property.

First I attach a handler to listen for the property changed event in the initialize method of my custom behavior:

initialize : function() {
PersistentCascadingDropDown.PersistentCascadingDropDownBehavior.callBaseMethod(this, 'initialize');
this.add_propertyChanged(this.test);
},

Again, I'm not sure if this is the correct way to attach a handler to the propertyChanged event. It is only an assumption (how exactly do I target only one of the many properties that raise propertyChanged events?).

Next is my event handling method.

test : function (sender, args)
{
if (args._propertyName == "SelectedValue")
{
// Throws an exception
alert(PersistentCascadingDropDown.PersistentCascadingDropDownBehavior.callBaseMethod(this, 'get_SelectedValue'));

// Alerts as undefined
alert(typeof(this.get_SelectedValue));

// Alerts that object doesn't support method
alert(this.get_SelectedValue());
}
},

Thanks again for your help.

Monday, March 26, 2012

Access nested properties

Hello everyone.
I have the following problem converning listview property binding.:
My classes are:
[DataObject]
public class Obj1 {
...
[DefaultValue ("New name")]
[DataObjectField (false)]
public string Name {
get { return this.name; }
set { this.name = value; }
}
[DataObjectField (false)]
public Obj2 Nested {
get { return this.nested; }
set { this.nested = value; }
}
...
}
and
[DataObject]
public class Obj2 {
...
[DefaultValue ("New name")]
[DataObjectField (false)]
public string Name {
get { return this.name; }
set { this.name = value; }
}
...
}

and then I use the ListView. It loads an array of Obj1 objects and successfully puts them in the listView
Then in my item template I have something like this: ...
<strong id="Strong3" runat="server">
<atlas:Label ID="name" runat="server">
<Bindings>
<atlas:Binding DataPath="Name" Property="text" />
</Bindings>
</atlas:Label>
</strong>
</td>
<td>
<strong id="Strong5" runat="server">
<atlas:Label ID="nested" runat="server">
<Bindings>
<atlas:Binding DataPath="Nested" Property="text" />
</Bindings>
</atlas:Label>
</strong>
The output is as expected : obj1.Name is shown as it is and obj1.Nested is shown as [object].
When I change:
<atlas:Binding DataPath="Nested" Property="text" />
to
<atlas:Binding DataPath="Nested.Name" Property="text" />
I get an empty text.
Any hints for that?
Thanks in advance

I don't think the current JSON serializer serializes the server-side properties to client-side properties. I think it only creates an object with public fields.
The DataPath in Binding only supports properties. The reason why the top-level field _does_ work is that the client-side DataRow overrides getProperty and returns a field (ie. calling myDataRow('Name') returns myDataRow['Name'], which equals to myDataRow.Name).

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.