Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Wednesday, March 28, 2012

Direct method call from html event

I'm just beginning trying to get familiar with Atlas and beforehead I'm curious whether it is possible to get a event handler called without having to execute the whole state flow of a page.Hi,

do you mean a server event handler? If so, the page must go through its whole lifecycle.

Difference between Callback and Webmethod

Hi,

What's the difference between using a callback event handler and a method defined as a WebMethod? One major difference I see is that a callback event involves some aspects of the page lifecycle. When is one advisable to be used over the other?

Thanks.

Hi,

On client side, the difference isn't very big. Both of them will use xmlHttpRequest to send to request to the server.

But it's different on server side. When work with callback, a new instance of the page is created to server the request, and a corresponding method defined in it will be fired. While with web method, no instance of page will be created, instead, an instance of the web service is created.

The latter one is a light-weighted way.

Monday, March 26, 2012

Design Question (Looking for your opinions)

I have a page that I need to call a method from my business tier. This method ussually will execute and complete quite quickly.

But because we are making and call to an external service. There are times where the network could be slow or the request gets sent but nothing comes back.

What I want to do is use ajax to make a call to the Business Layer. If it takes longer than say 5 secs. I want the ajax call to timeout and redirect to another page. Leaving

the process to complete on it's own (It doesn't return anything). The status of the "Async Job" will be checked somewhere else by the user.

Would this be an exceptable means of dealing with a long running task? We don't need the user to wait until it's complete.

Check out this for one example on long running queries...

http://www.west-wind.com/atlas/LongProgress/LongProgress.aspx

Maynot be exactly what you are looking for but...


That's a great example. Thank you very much.. I got it working :)

If I make the async call time out and call the function like so onTimeOut fires properly. If an error happens it goes to this method as well.

PageMethods.SendInfo(onComplete,onTimeOut);

If I make the async call error out OR time out and call the function like so PageMethods.SendInfo(onComplete,OnError,onTimeOut); both

timeouts & errors got the onError method.

Wednesday, March 21, 2012

Delegates on succes webservice call

Hi All,

I am writing a control where i would like to refer to a method inside my own control, see code below to make the situation clear:

var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false,null,this.WebserviceCallCompleted,this.WebserviceCallFailed,null, 10000);

First i do a webservice call which is working great! As you can see when the call succeeds the function WebserviceCallCompleted is invoked. In this method i would like to set a variable and start the rendering proces again. I do this with:this.Render;

WebserviceCallCompleted:function(result)

{

this._buttonText = result;

this.Render;

}

When i run this code the Render method isn't invoked. any ideas? should i use delegates?

Thanks in advance!

Regards,

To Resolve the this keyword use Function.createDelegate. Like:

var successHandler = Function.createDelegate(this, this.WebserviceCallCompleted);

var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false,null,successHandler,this.WebserviceCallFailed,null, 10000);


Hi KaziManzurRashid,

Thanks for your reply. I implemented your solution but it isn't working (yet) below you see what i have done:

InvokeWebservice:function()

{

var _completeHandler = Function.createDelegate(this,this.WebserviceCallCompleted);var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false, {"test":$get('txtfld1').value}, _completeHandler,this.WebserviceCallFailed,null, 10000);

}

,

WebserviceCallCompleted:function(result)

{

this.Render;

}

The WebserviceCallCompleted method is invoked so the delegate is implemented right. When i take a closer look at the this instance is see that 'this' is representing the right control and it contains a Render method but it still isn't invoked. Any idea?

Regards,


I could not find any reason the Render is not get executed, may be you should put this.Render() instead of this.Render.


hi KaziManzurRashid,

Very stupid but thats the trick i changed this.Render in this.Render() and it works. Probably there is a difference when you refer to a method when creating a delegate and when refering directly to it. I feel a little stupid! Thanks for your time and solutionBig Smile

Regards,

Declarative WebService call

Hi everybody

I just tried to call a method with MS-Ajax and the xml-script ... but in some way it doesn't work ...

This is the code:

-----------


<script type="text/xml-script">
<page xmlns="http://schemas.microsoft.com/xml-script/2005">
<components>
<label id="LbTest" /
<button id="BtTest">
<click>
<setPropertyAction target="LbTest" property="text" value="TestStarted" />
<invokeMethodAction target="CFCCall" method="invoke">
<parameters userContext="" />
</invokeMethodAction>
</click>
</button
<serviceMethodRequest id="CFCCall" url="Services/SCheck.asmx" methodName="Test.Web.CheckClass.Check">
<completed>
<setPropertyAction target="LbTest" property="text" value="TestCompleted" />
</completed>
<error>
<setPropertyAction target="LbTest" property="text" value="TestError" />
</error>
</serviceMethodRequest>
</components>
</page>
</script>

-----------

I got a check method in my checkclass in the webservice, which is in the namespace "Test.Web".

If I call this with JS directly, I'm getting my result - but if I'm doing it this way - I just get the "TestError" label-value. Any ideas?

Found the problem: It was the webservice - The webservice denies by default GET requests... does anyone know how I could switch the default method in xml-script to POST (i can't enable GET in the webservice, because I don't have access to it)... Or does someone know how I can call a Javascript in XML-script? Because with an JS I could make call and tell the call to use POST...