Wednesday, March 21, 2012

how can I pass a value to a javascript function on image clickBehavior atlas?

Hi Guys, I have the image template below and on imageURL I bind theDBImageName that comes from database via webservices objects. I also call a function DoAdditionalHandling because I need to construct the actual image URL. Now I need to define a click event which I am using theclickBehavior . How can I pass to the function a value that comes from database, let's say how can I passDBImageName field that is being bound to imageURL. Please advice!

<image id=

"ImageThumbPath">

<bindings>

<binding dataPath=

"DBImageName" property="imageURL" transform="DoAdditionalHandling" />

<binding dataPath=

"DBImageALT" property="alternateText" />

</bindings>

<behaviors>

<clickBehavior click=

"ImageClickHandler" />

</behaviors>

</image>

From your event handler, use the sender's dataContext to get the value, like so:

function imageClickHandler(sender, eventArgs){ var DBImageName = sender.get_dataContext().DBImageName;}

I just posted a working exmaple of this to my blog:http://smarx.com/posts/how-to-pass-a-value-to-a-javascript-event-handler.aspx.


Steve,

I asked you also the other day. Can you help me with<atlas:InitialDatarunat="server"id="InitialData1" >

I need to know how to specify the method name and the parameters to method. The example you showed me does not specify it, but it seems like it has its default methods because the web service on that example inherits froma dataservice. Please help me and give me more details if you can. I appreacite your help.


If I understand your question correctly, you want to specify what method to call on the web service (like using "loadMethod=..." on a dataSource in xml-script). Looking at theclass browser documentation for InitialData, it doesn't look like that's possible. :-(

Yes, the example works because it inherits from DataService and provides one method with the attribute [DataObjectMethod(DataObjectMethodType.Select)], so the right thing happens by default.


so any work around? Please advice.

Nothing that I'm aware of (but others please chime in if you have an answer).

I think you'll have to just not use <atlas: InitialData /> and just use your dataSource with autoLoad="true". InitialData is just there to improve performance a little by allowing you to send the data down with the initial page load instead of requiring a second roundtrip to the server.

I'll ping the product team and see if a LoadMethod parameter will be added to InitialData in the future.


is it anyway to specify the method call and parameters ondataSource with autoLoad="true? Please advice Steve!


Yes, just use the "serviceURL=..." and "loadMethod=..." properties on your <dataSource /> xml-script tag. I believe you can just specify <parameters foo="bar" baz="blah" ... /> inside your <dataSource /> to pass parameters.

If you need to databind those parameters, use <binding dataPath="..." property="parameters" propertyKey="foo" />.


not sure how. do u have the syntax of the datasource parameters? how can then I bind it to a dataview?

More explicitly, here's the syntax:

<dataSource id="myDataSource" serviceURL="myservice.asmx" loadMethod="myLoadMethod">
<parameters param1="foo" param2="bar" />
</dataSource>

(Assuming you have myLoadMethod(string param1, string param2); in your web service.)

Databinding your dataView doesn't need to change at all. It's still:

<dataView id="myDataView">
<bindings>
<binding dataContext="myDataSource" dataPath="data" property="data" />
</bindings>
</dataView>

I believe you already had this working in your code from theother thread.


I did that exactly and got a javascript error invalid xml mark up script. On the other example, I have it simply by clicking in a buton. But my other task is when page loads, the data has to be displayed.

I'll look into getting you a full working example.

To follow up on what I said earlier "I'll ping the product team and see if a LoadMethod parameter will be added to InitialData in the future," I checked with the product team, and it sounds like InitialData will have all the functionality of dataSource (so that includes specifying the method to call on the web service and any parameters), but they're not sure of the timeframe.


Thank you! Please email me atnesfrank@.yahoo.com

Steve,

Here is what I am doing but I get invalid xml mark up script. may be the syntax for parameters is diffrent? Please advice!

<dataSource id=

"dataSource1" autoLoad="true" serviceURL="~/AtlasTestService.asmx" loadMethod="GetTestData">

<parameters Code=

"cu0001" paramboolean="true" />

</datasource>


It's probably because your closing tag doesn't match your opening tag. Try changing "datasource" to the correct capitalization: "dataSource".

No comments:

Post a Comment