Mutual invocation of JS before and after table method

Source: Internet
Author: User

First, the foreground calls the backstage method:

1, in the background to write the method you want to call to the foreground, as follows:
Perform functions in C # code in JavaScript functions
public String str ()
{
Return "method of executing C # code in JavaScript method";
}

2, the front desk with JS can implement the method of invoking the background, as follows:
<script type= "Text/javascript" >
function Test () {
var a = "<%=str ()%>"; Methods for invoking C # backstage in JavaScript
alert (a);
}
</script>
Second, the background calls the foreground method:
1, in the foreground to write the background call JS method, as follows:
<script type= "Text/javascript" >

Method of calling JavaScript in function Test (param1, param2) {//c#
Alert (param1 + param2);
}
</script>

2, in the background to write a call to the foreground method, as follows:

C # code executes JavaScript methods and calls JavaScript methods
public void Ctojs (String param1,string param2)
{
Scriptmanager.registerstartupscript (this, this.) GetType (), "edit", "Test ('" + param1 + "', '" + param2 + "');", "true";
}
3, so you can invoke the foreground JS method in the background event, as follows in a click event called:
protected void Button1_Click (object sender, EventArgs e)
{
Ctojs ("Chinese 1", "Chinese 2");

}

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.