Call Webmethod from javascript

5 posts, 0 answers
  1. Prajakta
    Prajakta avatar
    5 posts
    Member since:
    Nov 2012

    Posted 16 Nov 2012 Link to this post

    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
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 21 Nov 2012 Link to this post

    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.
  3. Prajakta
    Prajakta avatar
    5 posts
    Member since:
    Nov 2012

    Posted 23 Nov 2012 Link to this post

    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
  4. Eyup
    Admin
    Eyup avatar
    3784 posts

    Posted 28 Nov 2012 Link to this post

    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.
  5. Prajakta
    Prajakta avatar
    5 posts
    Member since:
    Nov 2012

    Posted 29 Nov 2012 Link to this post

    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
Back to Top