html代码
<mce:script type="text/javascript"><!-- function getUserName() { Demo.ajax.GetUserName(document.getElementById("accout").value,getName); } function getName(respone) { document.getElementById("passowrd").value=respone.value; } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div> <p>帐号:<input id="accout" type="text" onchange="getUserName()" /></p> <p>用户名:<input type="text" id="passowrd" <mce:script type="text/javascript" src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js" mce_src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js"></mce:script><mce:script type="text/javascript" src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js" mce_src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js"></mce:script>/> </p> </div> </form> </body> </html>
asp.net 代码
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace Demo { public partial class ajax : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax)); } /// <summary> /// 获取用户名 /// </summary> /// <param name="account"></param> /// <returns></returns> [AjaxPro.AjaxMethod] public string GetUserName(string account) { string ok = (string)SqlHelper.ExecuteScalar(SqlHelper.connectionString, CommandType.Text, "select account from users where account='" + account + "'"); return ok; } } }
用上面的这种方法需要在简单的配置一下wen.config的httpHandlers 不然的话不可以运行
<add verb="*" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>