KP:
ReceiveServerData ReceiveServerData()
CallServer CallServer
==============================================================
= at .aspx.cs:
==============================================================
protected Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string cbRef = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
string cbScript = "function CallServer(arg, context) { " + cbRef + "; }";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServerScriptKey", cbScript, true);
}
}
#region ICallbackEventHandler Methods
private string callbackResult = "";
public string GetCallbackResult()
{
// 服务器处理完RaiseCallbackEvent事件后
// 返回给客户端一个值 callbackResult;
}
public void RaiseCallbackEvent(string eventArgument)
{
// eventArgument 是客户端通过调用 CallServer(arg, context)
// 时的arg参数传过来到server的值
// 此时应根据 arg的值生成 callbackResult的值
}
#endregion
==============================================================
= at .aspx:
==============================================================
<script language='javascript'>
<!--
function ReceiveServerData(arg, context)
{
// 服务器GetCallbackResult()返回的值
// 客户端在这里处理
}
function onchange()
{
// 客户端在这里生成发送到服务器的参数arg
// 服务器会以参数arg为eventArgument执行RaiseCallbackEvent(eventArgument)
//var list = document.getElementById("listParentClass");
//var selectedId = list.options[list.options.selectedIndex].value;
//CallServer(selectedId, null);
}
</script>