2、后台代码(把public改成protected也可以)
public string ss()
{
return("a");
}
2、在html里用<%=fucntion()%>可以调用
前台脚本
方法三:1、
3、pt language="javascript">
4、Argument;
theForm.submit();
}
-->
方法四:
〈!--用来存储你要调用的函数 --〉
在.CS里有:
public Page_OnLoad()
{
if (!Page.IsPost())
{
string strFunName=Request.Form["FunName"]!=null?Request.Form["FunName"]:"";
//根据传回来的值决定调用哪个函数
switch(strFunName)
{
case "enter()":
enter() ; //调用该函数
break;
case "其他":
//调用其他函数
break;
default:
//调用默认函数
7、break;
}
}
}
public void enter()
{
//……比如计算某值
}
方法五 直接用XHtmlRequest, client callback, javascript访问Web Service或WebMethod.
以访问WebMethod为例:
1、ScriptManager的EnablePageMethod必须为true.
HTML code
8、ts>
2、服务器方法必须是static方法
C# code
[System.Web.Services.WebMethod]
public static string[] GetStringArray(string s, int cnt)
{
string[] stringArray = new string[cnt];
Random rnd = new Ran
9、dom();
for (int i = 0; i < cnt; i++)
{
stringArray[i] = string.Format("Random{0}: {1}-{2}",i, s, rnd.Next(cnt));
}
//throw new Exception("亲爱的错误");
System.Threading.Thread.Sleep(3000);
return stringArray;
}
3、可以把script代码放到.js文件里,如Scripts目录下的MyScript.js内。
JScript co
10、de
function CallWebMethod(prefix,count)
{
$get('result').innerText = "请稍侯...";
PageMethods.GetStringArray(prefix, count, OnSuccess, OnFailed);
return false;
}
function OnSuccess(stringArray)
{
var s = "";
for(var i = 0; i < stringArray.length; i++)
{
s += stringArray[i] + "