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 :

[WebMethod]
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" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp: ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
<div>
&nbsp;</div>

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

function OnDoSomeSuccess()
{
alert('oluyor');
}
</script>
</body>
</html>

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.