html function change(obj) { var arr = MemberData1.FunAjax(obj.value).value; if( arr =="0") { document.getElementById('lblShow').style.display ='block'; document.getElementById('lblShow').innerText = '此帳號已經存在'; } else { document.getElementById('lblShow').style.display ='none'; } } cs private void Page_Load( object sender, System.EventArgs e) ... { if (! Page.IsPostBack) ...{ Ajax.Utility.RegisterTypeForAjax(typeof(MemberData1));//MemberData1中为页面的类名称 this.TextGAccount.Attributes.Add("onchange","javascript:change(this);"); InitailData();//新增會員 if (Request["callback"] != null && Request["callback"].ToString() == "3") ...{ Response.Write(BindAreaByAjax(Convert.ToInt16(Request["CityID"]))); Response.End(); } } } // 帳號驗證 [Ajax.AjaxMethod()] public static string FunAjax( string GAccount) ... { GuestCenter gct =new GuestCenter(); DataTable tab = gct.GSTA_SelMemberByGAcount(GAccount); if(tab.Rows.Count!=0) ...{ return "0"; //帳號存在 } return "1"; //帳號不存在 } 建立HttpHandler,在web.config里面加上 < configuration > < system .web > < httpHandlers > < add verb ="POST,GET" path ="ajax/*.ashx" type ="Ajax.PageHandlerFactory, Ajax" /> </ httpHandlers > < system .web > </ configuration >