首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

js实施后台代码

2012-09-23 
js执行后台代码HTML codescriptlanguagejavascriptdocument.write(%CsharpVoid()%)/scriptC#

js执行后台代码

HTML code
<script   language="javascript">document.write("<%CsharpVoid();%>");</script>

C# code
protected void CsharpVoid()     {         string strCC = "www.esoutong.com";         Response.Write(strCC);     }

我用的是onsubmit事件去调用JS函数,可是他执行的顺序是这样的,先去执行后台代码,把执行结果发回来,不我去触发我的JS函数时,是把刚才执行过(后台方法)的结果发出来,
我要的结果是当我去点按钮时,在去带参数去触发后台方法.怎么样写高手指点

[解决办法]
HTML code
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <script type="text/javascript">        function Say(strValue) {            PageMethods.SayH(strValue, ShowMsg);        }        function ShowMsg(result) {            var sResult = result.toString();            document.getElementById("rMsg").innerHTML = sResult;        }    </script></head><body>    <form id="form1" runat="server">    <div>        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />        <input id="Button1" type="button" value="点击我" onclick="Say('你是猪');" />    </div>    <div id="rMsg">    </div>    </form></body></html> 

热点排行