default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxPro;

namespace MyDemo
{
  public partial class _Default : System.Web.UI.Page
  {
    [AjaxPro.AjaxMethod]
    public DateTime GetServerTime()
    {
      return DateTime.Now;
    }
    [AjaxPro.AjaxMethod]

    public int AddTwo(int firstInt, int secondInt)
    {

      return firstInt + secondInt;

    }
    protected void Page_Load(object sender, EventArgs e)
    {
      AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
    }
  }
}

default.aspx

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
</head>
<body>
  <form >
    function getServerTime()
    {
      //MyDemo._Default.GetServerTime()得到从服务器传来的数据是object,要写.value
      alert(MyDemo._Default.GetServerTime().value);
    }
    function add(a,b)
    {
      //把文本框的值转换成int
      var a1 = parseInt(a);
      var b1 = parseInt(b);
      //第1、2参数为服务器方法所需要的参数,后面一个是如果服务器返回数据
      //客户端要处理这些数据的js函数名,他有个参数就是从服务器传来的数据
      MyDemo._Default.AddTwo(a1,b1,getAdd);
    }
    function getAdd(rel)
    {
      //要加上.value
      alert(rel.value);
    }
  </script>
</body>
</html>

相关文章:

  • 2022-12-23
  • 2021-10-02
  • 2021-09-06
  • 2021-11-29
  • 2022-12-23
  • 2021-07-14
猜你喜欢
  • 2021-07-01
  • 2022-01-27
  • 2021-10-24
  • 2021-11-05
  • 2021-08-27
相关资源
相似解决方案