_javascript techniques for the example of a parametric method in JS calling CS

Source: Internet
Author: User
In CS
Copy Code code as follows:

public string Test ()
{
Return to "Hello World";
}

ASPX page
Copy Code code as follows:

<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:
Copy Code code as follows:

public string Test (string a)
{
return A;
}

aspx
Copy Code code as follows:

<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>

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!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.