Showing posts with label bind. Show all posts
Showing posts with label bind. Show all posts

Saturday, March 24, 2012

How do I bind an event to a custom Javascript function?

So I'm tyring to do this in xml-script if possible. What I'm looking for is how to fire a javascript function I define, but declare it in the <completed></completed> tags of my <webMethod>. I did it in a roundabout way by binding it to an html control and applying a custom transform to that html control, but that feels like cheating. Any advice? Ideally it'd look something like:

<completed>

<invokeMethod target="MyJSFunction" method="invoke">

<bindings>

<binding id="something" dataContext="myWebMethod" datapath="result" property="parameters" propertyKey="inputVariable" />

</bindings>

</invokeMethod>

</completed>

But of course that's not quite right as I tried it and it didn't work...

Ok, I managed to solve this, but I'd like to know if there's a way to solve it w/o resorting to what I did. First, I just used the completed attribute of the <pageMethod> (see my .js extension athttp://forums.asp.net/thread/1342638.aspx at this point in the discussion, though, assume it's a serviceMethod, as the functionality is the same). So, my xml-script worked in this fashion:

<pageMethod method="MyMethodName" id="MyMethodId" completed="CustomJavascriptFunction">

<bindings>

<binding to input stuff />

</bindings>

</pageMethod>

That all worked, except that the eventArgs object being passed back as part of the 'completed' event was a Sys.EventArgs.Empty object, which I figured out after iterating over the properties and then digging into the .js again. For my solution, since I was using my custom 'Com.VelocityDataSolutions.PageMethodRequest' class anyway, I just changed the onMethodComplete function to pass the result variable to the target function. to do that I changed:

target.completed.invoke(target,Sys.EventArgs.Empty);

to

target.completed.invoke(target,result);

It works like I want now, my event handler grabs teh eventArgs object to use for its processing. I might change it to pass a more complex object (e.g. passing all the variables instead of just the result), but for now it works.

My real question, though, is did I have to go through all this? lol... If I wanted to do the same thing w/ a serviceMethod and didn't wantt o mod the atlas.js or subclass or anything, is there a way to pass the web service's output string to the event handler in declarative markup?

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