ASP.net中aspx与cs函数的互调

时间:2024-01-06 09:20:20

转载自:http://www.2cto.com/kf/201209/152898.html

aspx前台的script函数,调用aspx.cs中后台函数

aspx:

<script type="text/javascript">
function FrontFunction()
{
var RetStr=<%=BehindtFunction()%>;
alert(RetStr);
}
</script>

aspx.cs:

protected string BehindtFunction(object sender, EventArgs e)
{
//todo:执行代码
return "";//需要有返回值
}

aspx.cs中后台函数,调用aspx前台的script函数

aspx.cs:

protected string BehindtFunction(object sender, EventArgs e)
{
//代码
ClientScript.RegisterStartupScript(this.GetType(), "clear", "<script>FrontFunction()</script>");
return "";
}

aspx:

<script type="text/javascript">
function FrontFunction()
{
mask.style.visibility = 'visible';
Div2.style.visibility = 'visible';
} return false;
</script>