JS调用服务器方法并返回值
JS
function f_taxidchange()
{
CallServer1(document.getElementById(TaxIDFldName) ,TaxRateFldName);
}
function CallServer1(userControl)
{
arg = 'ServerMethod1|' + userControl.value;
<%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData1", "")%>;
}
function ReceiveServerData1(result)
{
document.getElementById("igtxtctl00_ContentPlaceHolder_SysTabEdit1_TaxRate").value=parseFloat(result);
}
C#
private string serverReturn;
public string GetCallbackResult()
{
string[] parts = serverReturn.Split('|');
return (string)GetType().GetMethod(parts[0]).Invoke(this, new object[] { parts[1] });
}
public void RaiseCallbackEvent(string eventArgument)
{
serverReturn = eventArgument;
}
public string ServerMethod(string arg)
{
object oday = DataAccessHelper.ExecuteScalar("select cast(BillingDay as varchar)+'+'+ItemCode from AR_BillItem where BillItemId='" + arg + "'");
return (oday == null) ? "0" : oday.ToString();
}
public string ServerMethod1(string arg)
{
object oday = DataAccessHelper.ExecuteScalar("select TaxRate from cf_tax where taxid = '"+arg+"'");
return (oday == null) ? "0" : oday.ToString();
}