当前位置: 代码迷 >> ASP.NET >> ASP.NET 后台怎么执行JS
  详细解决方案

ASP.NET 后台怎么执行JS

热度:3327   发布时间:2013-02-25 00:00:00.0
ASP.NET 后台如何执行JS
JScript code
<script>function turnoff(obj){document.getElementById(obj).style.display="none";}</script>


我CS页面想调用这个方法turnoff()
C# code
if(Sta=="1"){//执行turnoff('DIV2');}else{//执行turnoff('DIV1');}


怎么写呢?

------解决方案--------------------------------------------------------
response.write("<script>turnoff('DIV2');</script>");
------解决方案--------------------------------------------------------
楼主主要是应为前台做前台的事情,后台做后台的事情,前台需要调用后台的方法,可以用到ajax,后台需要调用前台,可以client.registerscript..............

------解决方案--------------------------------------------------------
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "abc", "<script>turnoff('DIV2')</script>", true);

------解决方案--------------------------------------------------------
C# code
        if (Sta == "1")        {            ClientScript.RegisterStartupScript(this.GetType(), "test", "turnoff('DIV2');", false);        }        else        {            ClientScript.RegisterStartupScript(this.GetType(), "test", "turnoff('DIV1');", false);        }
------解决方案--------------------------------------------------------
探讨
每次看到什么后台执行js,前台调用什么后台方法之类的脑残标题,都想吐槽,现在吐无可吐了。
  相关解决方案