JS Call Cs In a lot of ways, I use a simple method, as follows
In CS
public string Test ()
{
Return to "Hello World";
}
public string Test ()
{
Return to "Hello World";
}
ASPX page
<title> Untitled Page </title>
<mce:script type= "Text/javascript" ><!--
var demo=function () {
var b= "<%=test ()%>";
alert (b);
}
--></mce:script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "button" id= "Id1" onclick= "demo ()" value= "JS call cs"/>
</div>
</form>
</body>
<title> Untitled Page </title>
<mce:script type= "Text/javascript" ><!--
var demo=function () {
var b= "<%=test ()%>";
alert (b);
}
--></mce:script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "button" id= "Id1" onclick= "demo ()" value= "JS call cs"/>
</div>
</form>
</body>
The above is not with parameters, if the background CS method with parameters to be noted.
Cs:
public string Test (string a)
{
return A;
}
[C-sharp] View plaincopy
public string Test (string a)
{
return A;
}
aspx
<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>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "button" id= "Id1" onclick= "demo ()" value= "JS call cs"/>
</div>
</form>
</body>
<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>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "button" id= "Id1" onclick= "demo ()" value= "JS call cs"/>
</div>
& Lt;/form>
</body>
Call with Parameters ' <%=test (' +a+ ')%> ' must be in single quotes wrap ' <%=%> ', Inside again is double quotes. This is the key, otherwise the
call is unsuccessful!