serkan sendur 821 Postaholic Banned

Create Ajax Enabled WebSite. Set EnablePageMethods property of the ScriptManager to true : <asp: ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

In the CodeBehind of the page, register System.Web.Services namespace. Create a Method as follows :

public static void DoSome()


the method must be static and tagged as WebMethod.

In the .aspx page create a script and a button as follows :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="">
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp: ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

<input type="button" value="bas" onclick="PageMethods.DoSome(OnDoSomeSuccess);" />

function OnDoSomeSuccess()

When the button is clicked it calls the DoSome method and when it finishes executing it calls back the OnDoSomeSuccess function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.