C # foreground js calls the background code
Front-end js
<script type="text/javascript" language="javascript">
function Ceshi()
{
var a = "<%=Getstr()%>";
alert(a);
}
</script>
<Input type = "button" onclick = "Ceshi ();" value = "js call background code"/>
Background code
public string Getstr()
{
String aa = "Hello! ";
return aa;
}
C # Call the front-end js code in the background
Front-end js
<script type="text/javascript" language="javascript">
function Ceshi()
{
Var a = "Hello! "
alert(a);
}
</script>
<Asp: Button ID = "Button1" runat = "server" Text = "background call js"
onclick="Button1_Click" />
Background code
Protected void button#click (object sender, EventArgs e)
{
// Use the following code to call frontend js if UpdatePanel exists:
ScriptManager. RegisterStartupScript (UpdatePanel1,
This. Page. GetType (), "", "Ceshi ();", true );
// If not, use the following code:
This. Page. ClientScript. RegisterStartupScript (this. Page. GetType (),"",
"<Script> Ceshi (); </script>", true );
}