This is a migrated thread and some comments may be shown as answers.

Call Webmethod from javascript

4 Answers 600 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Prajakta
Top achievements
Rank 1
Prajakta asked on 16 Nov 2012, 05:34 PM
Hello,

I want to call WebMethod (HelloWorld) from Javascript, when I click on Telerik Button, which will display alert message box.

But I am always getting error as Webmethod Failed.

Am I missing anything?

It is working when use ASP.NET Button control and ScriptManager.
If you can give me any example, it would be helpful.

Thanks in advance.

Regards,
Prajakta Shevade

4 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 21 Nov 2012, 10:09 AM
Hi Prajakta,

Could you please share your page markup as well as the related code behind? Thus we will review the excat implementation you are trying to achieve and do our best to provide proper solution for your specific case.

Regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Prajakta
Top achievements
Rank 1
answered on 23 Nov 2012, 04:29 PM
Hello,

Thank you for replying...........
Here goes my code...........

<html>
<head runat="server">
   <script language="javascript" type="text/javascript">
        function callHelloWorld() {
            Trials1.WebService1.HelloWorld(OnComplete, OnError, OnTimeOut);
        }
        function OnComplete(arg) {
            alert(arg);
        }
        function OnTimeOut(arg) {
            alert("timeOut has occured");
        }
        function OnError(arg) {
            alert("error has occured: " + arg._message);
        }
    </script>
</head>

<body>
    <form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" EnablePageMethods="true" Runat="server">
                 <Services><asp:ServiceReference Path="~/WebService1.asmx" /></Services>
</telerik:RadScriptManager>

<div>
<telerik:RadMaskedTextBox ID="RadMaskedTextBox1" Runat="server" ClientEvents-OnBlur="callHelloWorld(); returns false;">
</telerik:RadMaskedTextBox>
</div>

</form>
</body>
</html>

------------------------------------------------- Web Service ---------------------------------------------------------------------------------

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _

Public Class WebService1
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function

End Class
------------------------------------------------------------------------------------------------------------------------------------------

I want to call webservice on blur of RAD maskedtextbox.

Thanks in advance....

Prajakta Shevade
0
Eyup
Telerik team
answered on 28 Nov 2012, 06:56 AM
Hello Prajakta,

You need to pass the name of the function to the RadControls client event and not the full javascript as with the asp controls:
<telerik:RadMaskedTextBox ... ClientEvents-OnBlur="callHelloWorld" AutoPostBack="false">
JavaScript:
function callHelloWorld(sender, args) {
   // execute custom logic
}

I hope this will prove helpful. Please give it a try and let me know about the result.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Prajakta
Top achievements
Rank 1
answered on 29 Nov 2012, 10:45 AM
Hello,

Thank you so much..... my problem got solved...

Thank you so much for your support......... your answers are precised....
 and very much helpful..........

Regards,
Prajakta Shevade
Tags
Ajax
Asked by
Prajakta
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Prajakta
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or