日期:2014-05-17  浏览次数:20435 次

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>