Hi,
I am trying to execute a code behind web method in javascript using PageMethods. The problem I am facing is as below:
Below is the javascript code and the insert method gets executed based on a confirm window:
The javascript code doesnt wait for the function to return a value and hence is executing the alert even before the insert function is complete. So, I end up getting an 'undefined' value for ret parameter.
Is there any way we can synchronously wait for the method to complete, get the return variable, set it in a hidden variable and use it in the rest of the javascript.
the webmethod does not have access to the UI controls on the page, as it is a shared web method.
I am open to moving this webmethod to a web service but I am not sure how the javascript would wait for the codebehind function to complete.
I have tried setTimeOut method in javascript to see if that will cause the wait but that dint work. The alert got fired with 'undefined'.
The webmethod does not take a long time to execute either. It only takes a few seconds. I just cant figure out how I can wait on the client side for the return parameter.
Please help me with any ideas and I am pretty much open to trying out anything at this point.
thanks in advance,
Kal.
I am trying to execute a code behind web method in javascript using PageMethods. The problem I am facing is as below:
<WebMethod()> _ |
Public Shared Function Insert(ByVal charge As String, ByVal clientid As String) As String |
Dim value as string |
'Do The insert and retun value |
Return value |
End Function |
Below is the javascript code and the insert method gets executed based on a confirm window:
function DoSomething1(sender, eventargs){ |
var txtRa = document.getElementById(sender.get_attributes().getAttribute("AssID")); |
txtRa.value=""; |
var charge = sender.get_text(); |
if (trim(charge)!=""){ |
charge = charge.replace("'", "\'"); |
var message = '<%= Resources.NoExist%>' |
if(confirm(message)) { |
var clientid = sender.get_attributes().getAttribute("ClientID"); |
var ret = PageMethods.Insert(charge,index); |
alert(ret); |
DoSomething2(ret); |
} |
The javascript code doesnt wait for the function to return a value and hence is executing the alert even before the insert function is complete. So, I end up getting an 'undefined' value for ret parameter.
Is there any way we can synchronously wait for the method to complete, get the return variable, set it in a hidden variable and use it in the rest of the javascript.
the webmethod does not have access to the UI controls on the page, as it is a shared web method.
I am open to moving this webmethod to a web service but I am not sure how the javascript would wait for the codebehind function to complete.
I have tried setTimeOut method in javascript to see if that will cause the wait but that dint work. The alert got fired with 'undefined'.
The webmethod does not take a long time to execute either. It only takes a few seconds. I just cant figure out how I can wait on the client side for the return parameter.
Please help me with any ideas and I am pretty much open to trying out anything at this point.
thanks in advance,
Kal.