I have a javascript that run every 5 mins. However, if the client is calling a webservice and wating for the result, i want to delay the script execution. So is there anyway to know that the client is calling to a webservice ?
Nothing out of the box, that I'm aware of. If you control the webservice call (e.g. calling it as a result of an event) then the simplest thing would be to populate a global boolean to true when the call gets sent and then change it to false in the onComplete and OnError handlers for the webservice.
Hi,MrVithan
Try the folloeing code:
Default.aspx:
<%@. Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title><script type="text/javascript">
// This function calls the Web Service method.
function EchoUserInput()
{
//Do something you want to do, e.g.delay the script execution
var echoElem = document.getElementById("EnteredValue");
WebService.HelloWorld(echoElem.value,SucceededCallback);
}
// This is the callback function that processes the Web Service return value.
function SucceededCallback(result)
{
var RsltElem = document.getElementById("Results");
RsltElem.innerHTML = result;
// Change the delay of the script execution back.
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
<div>
<h2>
Simple Web Service</h2>
<p>
Calling a simple service that echoes the user's input and returns the current server
time.</p>
<input id="EnteredValue" type="text" />
<input id="EchoButton" type="button" value="Echo" onclick="EchoUserInput()" />
</div>
</form>
<hr />
<div>
<span id="Results"></span>
</div>
</body>
</html>WebService.asmx:
<%@. WebService Language="C#" Class="WebService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(String input)
{
System.Threading.Thread.Sleep(3000);
string inputString = Server.HtmlEncode(input);
if (!String.IsNullOrEmpty(inputString))
{
return String.Format("You entered {0}. The current time is {1}.", inputString, DateTime.Now);
}
else
{
return "The input string was null or empty.";
}
}
}
Hope this helps.
Let me know if you need more info.
You can also see this thread for more help:http://forums.asp.net/t/1115018.aspx
No comments:
Post a Comment