JS Call Cs In a lot of ways, I use a simple method, such as the next, there is a need for friends can refer to
In CS
Copy Code code as follows:
public string test ()
{
return to "Hello World";
}
ASPX page
Copy Code code as follows:
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head runat= "Server" >
<title> Untitled page </title>
<mce:script type= "Text/javascript" ><!--
var demo=function () {
var b= "<%=test ()%>";
alert (b);
}
//--></mce:script>
</head>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "button" id= "Id1" onclick= "demo ()" value= "JS call cs"/>
</div>
</form>
</body>
</html>
The above is not with parameters, if the background CS method with parameters to be noted.
Cs:
Copy Code code as follows:
public string Test (string a)
{
return A;
}
aspx
Copy Code code as follows:
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head runat= "Server" >
<title> Untitled page </title>
<mce:script type= "Text/javascript" ><!--
var demo=function () {
var a= "Hello World";
var b= ' <%=test ("' +a+ '")%> ';//here must pay attention to the use of single and double quotes!!!!!
alert (b);
}
//--></mce:script>
</head>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "button" id= "Id1" onclick= "demo ()" value= "JS call cs"/>
</div>
</form>
</body>
</html>
Summary: Calls with parameters ' <%=test (' +a+ ')%> ' must be in single quotes wrap ' <%=%> ', with double quotes inside. This is the key, otherwise
The call is unsuccessful! The single and double quotes of all evils!!!