js調(diào)用CS里的方法有很多,我用一種簡(jiǎn)單的方法,如下
CS里
-
public string test()
-
{
-
return "Hello World";
-
}
aspx 頁(yè)面
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>無標(biāo)題頁(yè)</title>
-
<mce:script type="text/javascript" ><!--
-
var demo=function(){
-
var b= "<%=test() %>";
-
alert(b);
-
}
-
-
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<input type="button" id="id1" onclick="demo()" value="JS調(diào)用CS" />
-
</div>
-
</form>
-
</body>
-
</html>
上面的是不帶參數(shù)的,要是后臺(tái)CS里方法帶參數(shù)就要注意了。。
CS:
-
public string test(string a)
-
{
-
return a;
-
}
aspx:
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>無標(biāo)題頁(yè)</title>
-
<mce:script type="text/javascript" ><!--
-
var demo=function(){
-
var a="Hello World";
-
&n