nbsp;
说了这么多,我们来看看实际的例子吧:
Html前台代码:
<%@ Page Language="" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>回调练习</title>
<script type = "text/javascript" language ="javascript" >
function CallServerFunction(selectInfo,Num1,Num2)
{
//Arg是传向后台方法RaiseCallbackEvent()的参数,这里将操作符操作数一块传过去
Arg = selectInfo.selectedIndex + "/" + Num1.value + "/" + Num2.value;
//获取一个客户端函数的引用;调用该函数时,将启动一个对服务器端事件的客户端回调
<%= ClientScript.GetCallbackEventReference(this,"Arg","ReceiveServerData","null") %>
}
//接收回调后台传过来的结果数据,该函数名为GetCallbackEventReference()的第三个参数
function ReceiveServerData(result)
{
//js里面,必须用Label的innerText属性,用Text属性不会产生任何效果
lblShow.innerText = result;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type = "text" id="Num1" />
<select id="Oper" runat = "server">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<in