我有一个AjxLogin.cs文件,计划整合所有的Ajax函数,如下
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;/// <summary>
/// 计划整合所有的Ajax函数
/// </summary>
public class AjxLogin
{
    XReadXML XRML = new XReadXML();
    string XxmlTitleFile = "";
    public AjxLogin()
{
        AjaxPro.Utility.RegisterTypeForAjax(typeof(AjxLogin));
        XxmlTitleFile = HttpContext.Current.Server.MapPath("~/App_LocalResources/Title.xml");
}    [AjaxPro.AjaxMethod]
    public string getTitles(string XID)
    {
        return XRML.ReadStringsByID(XxmlTitleFile, "//titles/title", XID);
    }
    [AjaxPro.AjaxMethod]
    public DateTime GetServerTime()
    {
        return DateTime.Now;
    }
    [AjaxPro.AjaxMethod]
    public string isExistPassport(string txtPassPort)
    {
        if (txtPassPort == "a")
        {
            return ("1");
        }
        else
        {
            return ("0");
        }
    }
    
然后在其它的aspx页面里面调用它,例如
<script type="text/javascript">
function chkPassport(strPassPort)
{
    if((strPassPort==null)||(strPassPort==""))
    {
        document.getElementById("errtxtPassport").innerHTML="Please enter the passport";//Need Passport information;
    }
    else
    {
        if(AjxLogin.isExistPassport(strPassPort).value=="0")//Check the passport exist? 
        {
            document.getElementById("errtxtPassport").innerHTML="not exist this passport";//return the message on errors ocurrup
        }
        else
        {
            document.getElementById("errtxtPassport").innerHTML="";
        }
    }
}
</script>
其中AjxLogin.isExistPassPort是AjxLogin.cs中的AjxMethod,我该怎么调用它?

解决方案 »

  1.   

     [AjaxPro.AjaxMethod] 
        public string isExistPassport(string txtPassPort) 
        { 
            if (txtPassPort == "a") 
            { 
                return ("1"); 
            } 
            else 
            { 
                return ("0"); 
            } 
        } 
    ============================
     [AjaxPro.AjaxMethod] 
        public static string isExistPassport(string txtPassPort) 
        { 
            if (txtPassPort == "a") 
            { 
                return ("1"); 
            } 
            else 
            { 
                return ("0"); 
            } 
        } 
      

  2.   

    我之前是把AjaxMethod放在aspx.cs里面是好使的
    难道只能在每个aspx.cs里实现AjaxMethod?不能用公共的Class.cs文件去完成?
      

  3.   

    难道只能在每个aspx.cs里实现AjaxMethod?不能用公共的Class.cs文件去完成?
    =================================================================
    可以啊
      

  4.   

      AjaxPro.Utility.RegisterTypeForAjax(typeof(命名空间.类名)); 就可以实现
      

  5.   


    可以的啊,我都是写在公共类中的,你注册的时候就要注册这个公共类而不是aspx的类
    AjaxPro.Utility.RegisterTypeForAjax(typeof(公共类)); 
      

  6.   

    呵呵,可能ajaxPro用的少,还不透彻
      

  7.   

    我也是只放在 ASPX.CS文件里用的!!
      

  8.   


    我这么弄过了,客户端javascript里不认它,提示AjxLogin未定义