我有一个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,我该怎么调用它?
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,我该怎么调用它?
解决方案 »
- 如何将image类型的二进制数据在页面显示出图片(repeater绑定)
- 软考的数据库系统工程师
- 声音提示、弹出窗口提示
- 如何在SQL语句的like子句中使用正则表达式?
- 页面图片显示问题
- 请问如何根据表中某一字段的记录来决定DataList中的ImageButton的Visible?
- Treeview中的Selectexpands属性能不能只要其中的一部分功能?高手请入
- 关于定制自己的错误页面的问题,如何把自定义类的信息也放到页面里面
- 一个VS.NET很少见的错误,如果解决
- query的ajax问题success:function(data)不执行
- Image控件这么在.cs添加链接?
- Table加载数据的问题
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");
}
}
难道只能在每个aspx.cs里实现AjaxMethod?不能用公共的Class.cs文件去完成?
=================================================================
可以啊
可以的啊,我都是写在公共类中的,你注册的时候就要注册这个公共类而不是aspx的类
AjaxPro.Utility.RegisterTypeForAjax(typeof(公共类));
我这么弄过了,客户端javascript里不认它,提示AjxLogin未定义