ASP.NET中前台调用后台的方法

学习文章:http://www.cnblogs.com/kingteach/archive/2010/11/12/1875633.html

练习代码:

前台:

 1 <html xmlns="http://www.w3.org/1999/xhtml">
 2 <head runat="server">
 3     <title></title>
 4     <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
 5     <script language="javascript" type="text/javascript">
 6         $(document).ready(function () {
 7         });
 8 
 9         function CheckUnitNameExist() {
10             var name = $("#TextBox1").get(0).value;
11             PageMethods.CheckName(name, jsFunc);
12         }
13         function jsFunc(result) {
14             alert(result);
15         }
16     </script>
17 </head>
18 <body >
19 
20     <form id="form1" runat="server">
21      <asp:ScriptManager ID="ScriptManager1" runat="server"  EnablePageMethods="true">  </asp:ScriptManager>
22     <div>
23         请输入姓名:
24         <asp:TextBox ID="TextBox1"  runat="server" Width="200" onchange="CheckUnitNameExist()"></asp:TextBox>
25     </div>
26     </form>
27 </body>
28 </html>
View Code

后台:

 1 using System.Collections.Generic;
 2 using System.Linq;
 3 using System.Web;
 4 using System.Web.UI;
 5 using System.Web.UI.WebControls;
 6 using System.Web.Services;
 7 using System.Web.Script.Services;
 8 
 9 namespace htmltest
10 {
11     public partial class WebForm7 : System.Web.UI.Page
12     {
13         protected void Page_Load(object sender, EventArgs e)
14         {
15            
16         }
17 
18         [WebMethod]
19         public static string CheckName(string UnitName)
20         {
21             if (UnitName == "苏州")
22             {
23                 return "苏州的名字已存在!";
24             }
25             else
26             {
27                 return "可随意填写!";
28             }
29         }
30 
31     }
32 }
View Code


注意事项见学习文章.

转载于:https://www.cnblogs.com/hshuai/p/4224579.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值