The datasource only works with services that derive from DataService (afaik). If you want to bind a return value of a webservice method call (or page call I believe), you should use the ServiceMethod control. It works something like this:
A few things to note:
1. At this moment I don't believe there is a ServiceMethod server-control, and there are apparently issues with "code-behind" atlas files, so that is why I gave you an idea of how to do this all client-side.
2. If you want to bind against an actual data item itself, and not a property of that dataitem, you should be able to leave the datapath empty (or not define it at all).
3. In this example, the serviceMethod is invoked when the page is loaded. When the serviceCall is completed (ie. you got the return value from the service), the serviceMethod control will call your label's binding's "evaluateIn" method to actually "do" the
binding.
4. The binding is set to automatic=false because we don't want the binding to be "done" when the application is loaded. See #3.
receive a jscript error when I execute this code.
"constructor is null"
this part of the code:
<label targetElement="myNameLabel">
<bindings>
<binding id="myNameBinding" property="text" automatic="false" />
</bindings>
</label>
the binding is to the property text, but what is the source of the binding???
and how to call the serviceMethod with a parameter?
there is any "complete" documentation about what are the options, methods, properties etc... available for these objects?
How to implment this for all my links, not only 1 link?
How to retrieve the attribute "MyHelpID" and send it to the method?
I know I can do this using a Javascript and handle the over event of my A tag (<a onmouseover="displaythehelp(10)">....)
But there is a way to do this using the atlas scripts?
If you have a control that represents an HTML element, you can bind to properties of that HTML element. So, you should first add for example an atlas hyperlink control which renders those a tags.
Once you have such a hyperlink control, you can bind to one of the hyperlink's properties:
This code won't work however, since de dataPath basically says that the binding should call the HTML element (the a tag)'s get_myHelpID() function, which it does not have. You could probably get this working by adding such a get_myHelpID() function to the a-html
element's prototype, but you really don't want to go down that road.
A simpler solution for now would probably be to derive from hyperLink and add your own helpID property. Once you have done that, you can use your hyperlink and change the dataPath to dataPath="helpID".
Also, since you should use the hyperLink control in the first place to be able to bind to it, it is also kind of hard to actually set the "myHelpID" attribute on it... So, by adding your helpID property you make it possible to do this as well.
Willgart
Member
345 Points
70 Posts
binding atlas:label control to a page method?
Oct 06, 2005 01:39 AM|LINK
second try to display something in an <atlas:label> control...
again I have my "HelloWorld" webmethod which return a simple string.
maybe I can bind it to a label atlas control.
how to configure the atlas:datasource control, and the atlas:label control?
<atlas:DataSource runat="server" ID="dataSource1" ServiceUrl="mypage.aspx" />
....
<atlas:Label runat="server" ID="nameLabel"> <Bindings> <atlas:Binding DataPath="?????" Property="text" /> </Bindings> </atlas:Label>
Does I have to use the listview or itemview control? (if yes, again, any sample?)
thanks.
jerome
WilcoB
Participant
1454 Points
290 Posts
Re: binding atlas:label control to a page method?
Oct 06, 2005 06:20 PM|LINK
<serviceMethod id="myServiceMethod" serviceURL="MyService.asmx" serviceMethod="GetName">
<completed>
<invokeMethod target="myNameBinding" method="evaluateIn" />
</completed>
</serviceMethod>
<label targetElement="myNameLabel">
<bindings>
<binding id="myNameBinding" Property="text" automatic="false" />
</bindings>
</label>
<application>
<load>
<invokeMethod target="myServiceMethod" method="invoke" />
</load>
</application>
A few things to note:
1. At this moment I don't believe there is a ServiceMethod server-control, and there are apparently issues with "code-behind" atlas files, so that is why I gave you an idea of how to do this all client-side.
2. If you want to bind against an actual data item itself, and not a property of that dataitem, you should be able to leave the datapath empty (or not define it at all).
3. In this example, the serviceMethod is invoked when the page is loaded. When the serviceCall is completed (ie. you got the return value from the service), the serviceMethod control will call your label's binding's "evaluateIn" method to actually "do" the binding.
4. The binding is set to automatic=false because we don't want the binding to be "done" when the application is loaded. See #3.
Willgart
Member
345 Points
70 Posts
Re: binding atlas:label control to a page method?
Oct 06, 2005 11:36 PM|LINK
I prefer to play with server side controls to insure that there is no ID problems.
I have complex webpages and the ClientIDs generated are complex.
But for my first try with Atlas, I can implement my page like your sample.
Willgart
Member
345 Points
70 Posts
Re: binding atlas:label control to a page method?
Oct 07, 2005 12:06 AM|LINK
receive a jscript error when I execute this code.
"constructor is null"
this part of the code:
<label targetElement="myNameLabel">
<bindings>
<binding id="myNameBinding" property="text" automatic="false" />
</bindings>
</label>
the binding is to the property text, but what is the source of the binding???
and how to call the serviceMethod with a parameter?
there is any "complete" documentation about what are the options, methods, properties etc... available for these objects?
WilcoB
Participant
1454 Points
290 Posts
Re: binding atlas:label control to a page method?
Oct 07, 2005 08:08 PM|LINK
Did you add a corresponding html element as well, such as a <span id="myNameLabel"></span>, that the atlas control refers to? If not, please do so.
As for the serviceMethod with parameters: you can bind the parameters with for example a textbox. The code would look something like:
<serviceMethod ...>
<bindings>
<binding dataContext="myTextBox" dataPath="text" property="parameters" propertyKey="country" />
</bindings>
</serviceMethod>
<textBox targetElement="myTextBox" />
In this case, the value of the textbox will be passed as the country parameter to the service.
Willgart
Member
345 Points
70 Posts
Re: binding atlas:label control to a page method?
Oct 07, 2005 10:05 PM|LINK
yeah,
now I can call my method correctly...
next step...
I have a list of URLs, result of a gridview, in my page.
I want to display in a DIV (or a SPAN) the result of my GetName(param1) method (using the hover behavior)
the param1 will be a custom attribute in my <A> tag.
like:
<a href="mypage.aspx" MyHelpID="10">how to do this</a>
<a href="mypage2.aspx" MyHelpID="11">I want this</a>
<label targetElement="Span1">
<bindings>
<binding id="myNameBinding" property="text" dataContext="myServiceMethod" dataPath="response.object" automatic="false" />
</bindings>
<behaviors>
<hoverBehavior >
<hover>
<invokeMethod target="myServiceMethod" method="invoke" />
</hover>
</hoverBehavior>
</behaviors>
</label>
How to implment this for all my links, not only 1 link?
How to retrieve the attribute "MyHelpID" and send it to the method?
I know I can do this using a Javascript and handle the over event of my A tag (<a onmouseover="displaythehelp(10)">....)
But there is a way to do this using the atlas scripts?
thanks.
Jerome.
WilcoB
Participant
1454 Points
290 Posts
Re: binding atlas:label control to a page method?
Oct 08, 2005 09:53 AM|LINK
Once you have such a hyperlink control, you can bind to one of the hyperlink's properties:
<hyperLink targetElement="myLink" />
<label targetElement="mySpan">
....
<hover>
<invokeMethod target="myServiceMethod" method="invoke">
<bindings>
<binding dataContext="myLink" dataPath="associatedElement.myHelpID" property="parameters" propertyKey="helpID" />
</bindings>
</invokeMethod>
</hover>
</label>
This code won't work however, since de dataPath basically says that the binding should call the HTML element (the a tag)'s get_myHelpID() function, which it does not have. You could probably get this working by adding such a get_myHelpID() function to the a-html element's prototype, but you really don't want to go down that road.
A simpler solution for now would probably be to derive from hyperLink and add your own helpID property. Once you have done that, you can use your hyperlink and change the dataPath to dataPath="helpID".
Also, since you should use the hyperLink control in the first place to be able to bind to it, it is also kind of hard to actually set the "myHelpID" attribute on it... So, by adding your helpID property you make it possible to do this as well.