Step 1: Set EnablePageMethods property as True in Script Manager

<asp:ScriptManager ID=”ScriptManager1″ runat=”server” EnablePageMethods=”True” />

Step2: Write the function in xxxxx.aspx.cs file

public static int GetValue()
return 2;

Step3: if we need to call above function at client side then use the below code

<input type=”button” value=”Submit” onclick=”SubmitData()” />

• Write below functions in javascript file

function OnRequestComplete(result) {
function OnRequestError(error) {
if (error != null) {

function SubmitData() {
PageMethods.GetValue (OnRequestComplete, OnRequestError);