Showing posts with label properties. Show all posts
Showing posts with label properties. 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.

Accessing DropShadow properties through javascript

I am have trouble accessing the properties of a drop shadow through javascript. My dropshadow looks like this

<asp:Panel runat="server" id="registeredusersTab"></asp:Panel>
<atlasToolkit:DropShadowExtender id="dsregisteredusersTab" runat="server">
<atlasToolkit:DropShadowProperties targetcontrolid="registeredusersTab" opacity="0" rounded="false" trackposition="true">
</atlasToolkit:DropShadowProperties
And I'm trying to use the following script on click of another link...
<script>
$object('dsregisteredusersTab').set_Opacity(0);
</script
Its basically can't find dsregisteredusersTab. Any help would be greatly appreciated...

You need an ID on the properties object itself, not the extender. Check out the DropShadow sample page for an example of this:

<asp:Panel runat="server" id="registeredusersTab"></asp:Panel>
<atlasToolkit:DropShadowExtender id="dsregisteredusersTab" runat="server">
<atlasToolkit:DropShadowProperties targetcontrolid="registeredusersTab" opacity="0" rounded="false" trackposition="true"ID="dsBehavior">
</atlasToolkit:DropShadowProperties>

...

<script>
$object('dsBehavior').set_Opacity(0);
</script>


Thanks

Accessing control properties with js

hi,

i have a little server control (textbox with 2 properties minvalue, maxvalue). the client side ajax works.
how can i set/get a property using js?

var c = $get("MinMaxInt1");
c.set_minValue(2);// this doesn't work, "...object doesn't support property..."

thanks.

Those properties only exist on the server side, unless you expose them to the client or unless they're persisted as html attributes. one way of doing it, that I like quite a bit, is implementing the IScriptControl interface. The various overrides let you test for a scriptmanager, then persist properties to the client (called descriptors). See herehttp://ajax.asp.net/docs/tutorials/IScriptControlTutorial1.aspx for a tutorial, and feel free to ask for more help once you have.


sorry i didn't make it clearer.

i have implemented the interface and written client ajax script. the control works fine (validation input on the client side).
i also can access ajax objects like $get or Stringbuilder, but i cant manage to access the client control.

Her is the html (part) my aspx testpage generates:

<body>
<script type="text/javascript">
// call ajax
function SetMax()
{
var c = $get("MinMaxInt1");
// ? doesn't work ?
alert(c.get_maxValue());

/*
var sb = new Sys.StringBuilder("Hallo, ");
sb.append("Test");
alert(sb.toString());
*/

return false;
}
</script>

<form name="form1" method="post" action="Ajaxed.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQwNzg3ODExMWRkwx1FnvHkYJHkQ029ISA3vx6+SIQ=" />
</div>


<script src="http://pics.10026.com/?src=http://forums.asp.net/TestAMAT/ScriptResource.axd?d=gYiHX3BkJp5tz3FOyimNyJ_uWGddFi9na45DK4PBoE-dC7SG7dBm_AxXN4SsMhONOFwU_BALyPjA4waVfqk6C1vCKYWUbOpX6Fh-q_kbN8s1&t=633105269471562500" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=MinMaxInt.js" type="text/javascript"></script>

<div>


<input name="MinMaxInt1" type="text" id="MinMaxInt1" /><br />

<input type="submit" name="Button1" value="MaxValue 50" onclick="return SetMax();" id="Button1" />

</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLBnftKAsjcs4ACAoznisYGgdiG7kpUnfViFn4d4o68YWG/Jmk=" />
</div>

<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(VisControls.MinMaxInt, {"maxValue":100,"minValue":1}, null, null, $get("MinMaxInt1"));
});
// -->
</script>
</form>


Right, ok, I see now. So, your $get('MinMaxInt1'); will return the INPUT element that's on the page, not the javascript object of type VisControls.MinMaxInt that you $created. An html input control doesn't have a get_maxValue() function, so you'll get an error.

Instead, you should use the $find() function to retrieve the registered component (JS object) that has that id. So, your function should be:

var c = $find('MinMaxInt1')

alert(c.get_maxValue());


thanks, it now works.


Coool, dont' forget to mark it as an 'answer' then.

Monday, March 26, 2012

Accessing complex data properties on the client side.

I'm trying to access the properties of an object passed back from a web service but am having trouble. I thought the syntax was...

results.getItem(i).getProperty(

'propertyname') but I'm getting an error 'results.getItem(i).getProperty' is not a function.

I'm able to bind 'results' to a listview fine on the client side and debug.dump shows the data being returned is correct.

i don't know what type 'results' is.
you can try to use code below to list methods and propertis of getItem(i)
function(obj)
{
for(var name in obj)
names+=name+"\n";
alert(names);
}

tonyqus:

i don't know what type 'results' is.
you can try to use code below to list methods and propertis of getItem(i)
function(obj)
{
for(var name in obj)
names+=name+"\n";
alert(names);
}

Sorry tonyqus, 'results' is a generic collection and the javascript function on the client returns '_serverType' and the property names of the objects (similar to debug.dump). If I return a datatable the following works fine.

for (var i = 0; i < results.get_length(); i++) { alert(results.getItem(i).getProperty("PropertyName"));}
Is there a way to do something similar with object collections? The object collection binds fine to a listview or select element using set_data(results) so there must be some way of referencing the properties in javascript.

Never mind:!

Came back to it today and looked a little closer at the response from fiddler for a datatable vs an object collection. Also looked a little closer at JSON (http://www.json.org/). The line results.getItem(i).getProperty("PropertyName") works with datatables where results[i].PropertyName works with collections.

Access User Controls in Web Service

Hello all,

We have a custom control that has many custom properties and methods. Currently this control is being loaded through the Master page and it is working just fine. Now there is a need to load this control through a web service.

Since the control needs to be loaded through a web service, the web service does not have any information on this custom control and its properties/methods. We can only load this custom control as a System.Web.UI.UserControl, and we cannot also cast this UserControl as a custom control because the web service does not know anything about this custom control.

I read this article about rendering user controls through web service by Scott Gutherie but it only talks about user control and not custom controls and custom properties and methods.

http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx

Does anybody have any ideas on how to access the custom control in a web service?

Thanks.

Hi,

For custom control, it's necessary to add reference to it in the web application. And instantiate it with its actual constructor.

Then, you may render it in a similar way as Scott Gutherie has shown.

Access Properties in codebehind

How can i access properties of DragPanel in codebehind?

For example, in test.aspx i have DragPanel, i want change the DragHandleID property in codeBehind... ? I cant access it. Thanks for any reply.

ThoNT

Assuming it's the first one in the list...

dragPanelExtender1.TargetProperties[0].DragHandleID = "newHandleID";


sburke_msft:

Assuming it's the first one in the list...

dragPanelExtender1.TargetProperties[0].DragHandleID = "newHandleID";

but if's not the first one in the list... and we dont know the index of it. (because we creat it by an for looping)


Well you can also look at the TargetID property to see which control it's extending

Hi ThoNT,

I think the easiest way to dynamically get the properties is to use the control you attached the extender to (i.e. the control you're setting as the "TargetControlID"). You can just do the following:

DragPanelProperties properties = dragPanelExtender1.GetTargetProperties(myControl1);if (properties !=null){ properties.DragHandleID ="newHandleID";}

Thanks,
Ted


Thank Ted Glaza.

i have just know functionGetTargetProperties from you!

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).