AjaxPro.2 的使用记录

1. Bin 下添加引用 AjaxPro.2.dll

2.添加web.config

  

<system.web>
<httpHandlers>
            <add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
</system.web>

3.在页面的后台文件(xx.cs)文件中注册

public partial class CompanyRegister : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //注册
        AjaxPro.Utility.RegisterTypeForAjax(typeof(CompanyRegister));
    }
}
    //检查企业名称
    [AjaxPro.AjaxMethod]
    public string CheckCompanyName(string agencyName)
    {
        DataAccess SqlHelper = new DataAccess(DataAccess.eConnectionDB.SystemDB);
        try
        {
            string _n = DataHelper.GetSafeString(agencyName);

            DataTable dt = SqlHelper.GetDataTable("SELECT JGMC  FROM sme_serviceAgency where JGMC='" + _n + "'");

            if (dt != null && dt.Rows.Count > 0)
            {
                return "1";
            }
            else
            {
                return "0";
            }
        }
        catch
        {
            return "1";
        }
    }

4.前台代码文件的使用

function CheckComPanyName() {
    $("#agencyNameTip").html("正在验证....");

    var comchk = CompanyRegister.CheckCompanyName($("#agencyName").val()).value;

    if (comchk == "0") {
        alert ('注册成功');
    }
    else {
        alert('用户名已被注册');
    }
}
原文地址:https://www.cnblogs.com/challengesoflife/p/2821290.html