7.前台Js调用后台方法,后台调用前台JS
1.前台,后台
前台:<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>UntitledPage</title>
<script language="javascript" type="text/javascript">
functionhelloword(){
vara="<%=helloword()%>";
alert(a);
}
</script>
</head>
<body οnlοad="helloword()">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
后台:public partial class _Default : System.Web.UI.Page
{
protected voidPage_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this,this.GetType(),"","alert(helloword())",true);
}
public string helloword()
{
string a = "helloword!";
return a;
}
}