Sorry about my last post which is unreadable...
Reposted:
Weird, but I just tried to create a page just like yours and it works even if the static method is in the code behind...
This is the class:
public partial class _Default : System.Web.UI.Page
{
[WebMethod]
public static string GetServerDate()
{
return DateTime.Now.ToString();
}
}
And this is the ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="~/Default.aspx.cs" Inherits="_Default" %>
<%@ Import namespace="System.Web.Services"%>
<!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" method="post">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<input type="button" value="get date" onclick="GetDate();" id="Button1" />
<div id="date" />
</div>
</form>
</body>
</html>
<script type="text/javascript">
function GetDate()
{
var div = document.getElementById("date");
PageMethods.GetServerDate(function (result)
{
div.innerText = result;
});
}
</script>