zoukankan      html  css  js  c++  java
  • 前台调用后台事件的方法

    前台:

    <html>
    <head id="Head1" runat="server">
      <meta http-equiv="content-type" content="text/html;charset=gb2312" />
      <script src="../../js/jquery-1.3.2.js" type="text/javascript"></script>
    </head>
    <body>
    <input type="button" value="调用Test" onclick="CallMethod('Test')"/><input type="button" value="调用Test1" 

    onclick="CallMethod('Test1')"/><input type="button" value="调用Test2" onclick="CallMethod('Test2')"/>
    <script type="text/javascript">
        function CallMethod(method){
            $.ajax(
      {
          type: "POST",
          url: "WebForm1.aspx",
          data: { method: method },
          success: function(msg) { alert(msg); },
          error: function() { alert('出错了'); }
      }
      )
        }

    </script>
    </body>
    </html>

    后台:

     protected void Page_Load(object sender, EventArgs e)
            {
                Response.Charset = "gb2312";
                if (Request.Form["method"] == "Test") Test();
                else if (Request.Form["method"] == "Test1") Test1();
                else if (Request.Form["method"] == "Test2") Test2();

                Response.Write("一般请求<br/>");


            }


            [System.Web.Services.WebMethod]
            public static string SayHello()
            {
                return "Hello Ajax!";
            }


            public void Test()
            {
                Response.Write("执行Test方法" + DateTime.Now);
                Response.End();//停止其他输出
            }
            public void Test1()
            {
                Response.Write("执行Test1方法" + DateTime.Now);
                Response.End();//停止其他输出
            }
            public void Test2()
            {
                Response.Write("执行Test2方法" + DateTime.Now);
                Response.End();//停止其他输出
            } 

  • 相关阅读:
    远程网络时间同步在分布式测控与实时仿真系统应用
    GPS对时装置(北斗卫星同步时钟)应用市场调研分析
    时间同步服务器(NTP时钟同步服务器)如何正确的选购?
    NTP授时服务器(卫星同步时钟)与物联网十大应用
    App 自动化环境搭建(基于 Appium)
    let var作用域
    vue methods和computed效率比较
    vue computed
    vue computed
    vue v-bind:style
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090582.html
Copyright © 2011-2022 走看看