Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
how do i call a function written in test.aspx.cs from a javascript in test.aspx?? Is that possible?


Thanks in advance

[Agent_Spock]
- Added appropriate tag
- changed question header
Posted
Updated 26-May-14 20:02pm
v2
Comments
karthik Udhayakumar 27-May-14 2:03am    
Check this there is a lot in the internet,
http://www.dotnetspark.com/kb/1453-call-server-side-function-using-jquery-asp-net.aspx
pls frame better questions further
HK33 27-May-14 2:49am    
:-)

Yes, That is possible

Make the methods written in test.aspx.cs as webmethod

C#
[WebMethod(EnableSession = false)]
 public static string testfunction(string param)
 {
     return "abc";
 }


Call this function via jquery ajax call

function ajaxFunction() {
           $.ajax({
               type: "POST",
               url: "test.aspx/testfunction",
               data: "{param: " + page + "}",
               contentType: "application/json",
               dataType: "json",
               success: function (msg) {
                   OnSiteManagementSuccess(msg.d);

               },
               error: function (msg) { msg.responseText; }
           });
       }


call this ajax function as per your requiremnt
 
Share this answer
 
Comments
Nirav Prabtani 27-May-14 3:12am    
my 5+
Hi,

First way using WebMethod : http://www.c-sharpcorner.com/UploadFile/rohatash/calling-server-side-function-from-javascript-in-Asp-Net/[^]

To call a Control Event :

JavaScript
<input type="button" onclick="__doPostBack('[Your Control Unique ID','[Function Name]')" />
 
Share this answer
 
see here[^]
 
Share this answer
 

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