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");
}