Add Web Page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Lab1.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="scriptmanager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<button onclick ="GetDate()">Click me</button>
</div>
</form>
<script>
function GetDate() {
PageMethods.GetCurrentDate(onSuccess);
}
function onSuccess(response) {
alert(" Current Date " + response);
}
</script>
</body>
</html>
Add the following code in WebForm2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string GetCurrentDate()
{
return System.DateTime.Now.ToString();
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Lab1.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="scriptmanager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<button onclick ="GetDate()">Click me</button>
</div>
</form>
<script>
function GetDate() {
PageMethods.GetCurrentDate(onSuccess);
}
function onSuccess(response) {
alert(" Current Date " + response);
}
</script>
</body>
</html>
Add the following code in WebForm2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string GetCurrentDate()
{
return System.DateTime.Now.ToString();
}