客户端控件触发不刷新页面

来源:互联网 发布:淘宝卖家首页怎么登陆 编辑:程序博客网 时间:2024/06/04 19:14

onBlur事件就是当光标离开文本框中时发生的事件。

当在文本框中离开时需要到数据库中取数据到其他框中,而不是以前用change事件去处理

1)

<asp:TextBox runat ="server" ID ="txtShipper" onblur="javascript:getShipper();" MaxLength="30" >

2)在.js文件中加入

function getShipper()
{
var _o=document.getElementById ("txtShipper");
PageMethods.CallBackShipper(_o.value,completeShipper,error);
}

function completeShipper(result)
{

valuesArr=result.split("//");
document.getElementById("txtShipper_name_in_Invoice").value=valuesArr[0];
document.getElementById("txtShipperFaxNo").value=valuesArr[1];
document.getElementById("txtShipper_Fax_Country_code").value=valuesArr[2];
}

 

3)设置ScriptManager的EnablePageMethods="true"

<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true"
EnableScriptLocalization="true" EnablePageMethods="true" >

4)在后台.cs代码中添加

[System.Web.Script.Services.ScriptMethod]
[System.Web.Services.WebMethod]
public static string CallBackShipper(string inputValue)
{
ChargeCommonBLL bll = new ChargeCommonBLL();
CustomInfo info = bll.GetCustomInfo(inputValue);

string returnValues = info.CustEName1 + "//" + info.FAX + "//" + info.Country;
return returnValues;
}