Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am developing an online app in which i need to call vb.net(asp.net) functions form javascript that are fired on drag and drop events. so how can i call server side functions and pass parameters to the function using javascript....
Posted

XML
You can use the PageMethods to call server side function (C#) from ClientSide(Javascript)



1) Add a script Manager to your page and set the 'EnablePageMethods' property of script manager to True.

<asp:ScriptManager ID="ScriptManager2" runat="server" EnablePageMethods="true"/>
2) Add Javascript function to the body section of page

<body>
    <form id="form1" runat="server">
    <script type="text/javascript">
        function CallingServerSideFunction() {
            PageMethods.GetData();
        }
    </script>
    </form>
</body>
3) Add the method you want to call in c#

    //Please note that the method should be a Static and WebMethod.
    [System.Web.Services.WebMethod]
    public static void GetData()
    {
        MessageBox.Show("Calling From Client Side");
        //Your Logic comes here
    }
4) Calling the Javascript function

<input id="Button2" type="button" value="FunctionCall" onclick="CallingServerSideFunction()" />
 
Share this answer
 
Comments
[no name] 23-Mar-14 13:55pm    
its not firing in my case , can any one tell me reason why i am using telrik script manager like this

<telerik:RadScriptManager runat="server" ID="RadScriptManager1" EnablePageMethods="true" />
naushad208 26-Nov-14 3:48am    
How many ways to call server side function by JavaScript.Please Explain all ways with examples

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900