读书人

js实施后台代码

发布时间: 2012-09-23 10:28:10 作者: rapoo

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> 

读书人网 >asp.net

热点推荐