方法五 直接用XHtmlRequest, client callback, javascript访问Web Service或WebMethod.
以访问WebMethod为例:
1、ScriptManager的EnablePageMethod必须为true.
HTML code
2、服务器方法必须是static方法
C# code
[System.Web.Services.WebMethod]
public static string[] GetStringArray(string s, int cnt)
{
string[] stringArray = new string[cnt];
Random rnd = new Random();
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 code
function CallWebMethod(prefix,count)
{
$get('result').innerText = "请稍侯...