The parametric method in JS calling CS

Source: Internet
Author: User
Tags xmlns

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!  

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.