客户端的异步调用

在脚本中实现方法的异步调用
1。在页的Page_Load中注册
        AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));//_Default当前页的类名

2。在异步调用的方法前加[AjaxPro.AjaxMethod()]
    /// <summary>
    /// 验证用户是否有权限查看历史记录
    /// </summary>
    /// <param name="UserName">用户名</param>
    /// <param name="OpType">操作类型</param>
    /// <param name="CID">公司ID号</param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod()]
    public bool ValidateUser(string UserName,string OpType, string CID)
    {
        try
        {
            string TableName = null;
            string RoleType = null;//用户查看指定的类型时在对应的角色名
            switch (OpType.Trim ())
            {
                case "公司基本信息":
                    TableName = "Law_Company";
                    RoleType = "普通用户";
                    break;
                case "营业执照信息":
                    TableName = "Law_ShopCard";
                    RoleType = "营业执照类";
                    break;
                case "资本分配信息":
                    TableName = "Law_Capital";
                    RoleType = "资本股东类";
                    break;
                case "事务所及其它":
                    TableName = "Law_Office";
                    RoleType = "事务所类";
                    break;
            }

            string ValidataValue = CompanyInfo.ValidateUser(UserName, TableName, "历史变更", CID, RoleType);

            if (ValidataValue == "Yes")
            {
                return (true);
            }
            else
            {
                return (false);
            }
           
        }
        catch (Exception ee)
        {
            throw new Exception(ee.Message);
        }

        return (false);
    }


3。javascript脚本
    function Validate (OID,OPType,UserNameID,PwdID,CID,disr1ID,t1ID)
    {
      var txtUserName = document.getElementById (UserNameID);//验证用户对话框中的用户名文本框
      var txtPassword = document.getElementById (PwdID);//验证用户对话框中的密码的文本框
      var disr1 = document.getElementById (disr1ID);//查询隐藏的行的对象
      var t1 = document.getElementById (t1ID);//获得用于显示历史记录但要验证的身份的标签
     
      if (txtUserName.value == "")//验证是否输入用户名
      {
        alert ("没有输入用户名,请输入验证的用户名!");       
        return false;
      }
     
      if (txtPassword.value == "")//验证是否输入密码
      {
        alert ("没有输入密码,请输入验证的密码!");
        return false;
      }
     
      if (txtUserName.value != "" && txtPassword.value != "")
      {
        var IsLegalityUser = _Default.ValidateLegalityUser(txtUserName.value,txtPassword.value).value;//验证用户是否是合法用户
        var IsValidate = _Default.ValidateUser (txtUserName.value,OPType,CID).value;//验证用户是否有合法的权限
       
        if (IsLegalityUser && IsValidate)
        {
           showInfo (OID);
           disr1.style.display = "block";//显示隐藏的标签控件
           t1.style.display = "none";
        }
        else
        {
          alert ("对不起," + txtUserName.value + "用户没有权限查看" + OPType + "历史记录!");
          return false;
        }
       
      }
    }

你可能感兴趣的:(异步调用)