內部WebService呼叫,AJAX機制

public partial class Test1 : System.Web.UI.Page
{
public int i;
protected void Page_Load(object sender, EventArgs e)
{
string js = "";
js += "function Call_IsDuplicate(){";
//js += " alert($get('" + Name.TextBox.ClientID+ "').value);";
js += " var str = $get('" + TextBox1.ClientID + "').value;";
js += " if (str.indexOf(\"'\") >= 0 ){";
js += " $get('" + TextBox1.ClientID + "').value = str.replace(/'/g,'');";
js += " }";
js += " PageMethods.IsDuplicateResume($get('" + TextBox1.ClientID + "').value,Receive_IsDuplicate);";
js += "}";
js += "function Receive_IsDuplicate(data){";
js += " if (data){";
js += " $get('" + Label1.ClientID + "').innerHTML = '名稱已重複。';";
js += " }";
js += " else{";
js += " $get('" + Label1.ClientID + "').innerHTML = '名稱未重複';";
js += " }";
js += "}";


ClientScript.RegisterStartupScript(this.GetType(), "DuplicateNameService", js, true);

// TextBox1.Attributes.Add("onchange", "Call_IsDuplicate();");
// TextBox1.Attributes.Add("onKeyUp", "Call_IsDuplicate();");
// TextBox1.Attributes.Add("onBlur", "Call_IsDuplicate();");

}

//

//宣告呼叫方式
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod()]

public static bool IsDuplicateResume(string chinese_name)
{
//int i;

//return true;

後端執行的程式碼撰寫處
return Resume.IsDuplicateName(chinese_name);

}
}

0 意見: