• 前台调用后台事件的方法


    前台:

    <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();//停止其他输出
            } 

  • 相关阅读:
    面试题准备
    ImageList控件
    修改Visual Studio 2010 帮助文件库的位置
    委托与事件(续)
    PictureBox
    我的廣播情緣12/26
    回首我的2007 12/25
    水晶報表:列印支票金額12/12
    聖誕節快樂
    新年快樂
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090582.html
Copyright © 2020-2023  润新知