日期:2014-05-20  浏览次数:20804 次

如何在服务端调用客户端的js函数?
如题,最好有简单易懂的例子,因为如果用response.write()写的话会出现在页面代码最上面,这样就找不到定义了.但是我想用下面定义的js函数,该怎么做?

------解决方案--------------------
ASP.NET 可能吗!!!!!

除非是你自己的服务器端和客户端。





------解决方案--------------------
up
------解决方案--------------------
response.write(js) 是在页面加载之前执行 js代码 当然就找不到了
response.write( "body.onload=js ") 页面加载后执行js就可以了,具体不是这么写大体上就这个意思
------解决方案--------------------
前台方法:
<script type= "text/javascript ">
function testAlert()
{
alert( "猪头 ");
return false;
}
</script>

后台C#:
protected void Button1_Click(object sender, EventArgs e)
{
String csname1 = "PopupScript ";
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = "testAlert(); ";
cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}
}