当前位置: 首页 > news >正文

[英语阅读笔记]Using Page Methods in ASP.NET AJAX

原文地址:http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx
作者:Timothy Khouri

看标题很容易联想到updatepanel方式的页面方法调用,而文中所指的是在客户端异步调用webservice的方式.而且用了很简洁的代码来说明调用的方法.

作者用一个contact us页来描述.

首先建立一个表单:

Our "Contact Us" Form In ASP.NET

< form runat ="server">
   < asp:ScriptManager ID ="ScriptManager" runat ="server"
        EnablePageMethods ="true" />
   < fieldset id ="ContactFieldset">
       < label>
           Your Name
           < input type ="text" id ="NameTextBox" />< /label>
       < label>
           Email Address
           < input type ="text" id ="EmailTextBox" />< /label>
       < label>
           Your Message
           < textarea id ="MessageTextBox">< /textarea></label>
       < button onclick ="SendForm();">
           Send< /button>
   < /fieldset>
< /form>

 
然后是webservice文件


Our Page Method Exposed to ASP.NET AJAX

using System;
using System.Web.Services;

public partial class ContactUs : System.Web.UI.Page
{
   [WebMethod]
    public static void SendForm( string name, string email, string message)
   {
        if ( string.IsNullOrEmpty(name))
       {
            throw new Exception( "You must supply a name.");
       }

        if ( string.IsNullOrEmpty(email))
       {
            throw new Exception( "You must supply an email address.");
       }

        if ( string.IsNullOrEmpty(message))
       {
            throw new Exception( "Please provide a message to send.");
       }

       // If we get this far we know that they entered enough data, so

       // here is where you would send the email or whatever you wanted

       // to do :)

   }
}


最后是表单文件里需要调用的javascript


function SendForm() {
    var name = $get( "NameTextBox").value;
    var email = $get( "EmailTextBox").value;
    var message = $get( "MessageTextBox").value;

   PageMethods.SendForm(name, email, message,
       OnSucceeded, OnFailed);
}

function OnSucceeded() {
   // Dispaly "thank you."

   $get( "ContactFieldset").innerHTML = "<p>Thank you!</p>";
}

function OnFailed(error) {
   // Alert user to the error.

   alert(error.get_message());
}


所有的一切经过原文作者描述后会发现,原来是这么简单.

转载于:https://www.cnblogs.com/aspnetx/archive/2007/06/21/791438.html

相关文章:

  • 设计模式学习笔记(三:装饰模式)
  • 釜底抽薪:用autoruns揪出流氓软件的驱动保护
  • IT培训Linux文件的复制、删除和移动命令
  • nested exception is org.hibernate.HibernateException: No Session found for current thread
  • SAP BC404 课程中文自学笔记
  • 我的老师孔庆东
  • MS SQL入门基础:SQL数据库表的修改
  • Spring源码学习之:模拟实现BeanFactory,从而说明IOC容器的大致原理
  • photoshop之蒙板(又称遮罩)的使用
  • 最新思科考试中心查询
  • 扩展 TreeView 实现选择 CheckBox 自动回发
  • 苏州印象
  • JS实现搜索关键字加亮效果
  • 使用redis做mybaties的二级缓存(2)-Mybatis 二级缓存小心使用
  • [转]SQL中CONVERT转化函数
  • 【跃迁之路】【444天】程序员高效学习方法论探索系列(实验阶段201-2018.04.25)...
  • Android单元测试 - 几个重要问题
  • Angular 响应式表单之下拉框
  • canvas绘制圆角头像
  • Java程序员幽默爆笑锦集
  • k8s如何管理Pod
  • SOFAMosn配置模型
  • 从tcpdump抓包看TCP/IP协议
  • 短视频宝贝=慢?阿里巴巴工程师这样秒开短视频
  • 类orAPI - 收藏集 - 掘金
  • 面试总结JavaScript篇
  • 如何将自己的网站分享到QQ空间,微信,微博等等
  • 深入浅出Node.js
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • 用mpvue开发微信小程序
  • 在Mac OS X上安装 Ruby运行环境
  • AI又要和人类“对打”,Deepmind宣布《星战Ⅱ》即将开始 ...
  • ​2020 年大前端技术趋势解读
  • %3cscript放入php,跟bWAPP学WEB安全(PHP代码)--XSS跨站脚本攻击
  • (42)STM32——LCD显示屏实验笔记
  • (Redis使用系列) Springboot 使用redis实现接口Api限流 十
  • (TipsTricks)用客户端模板精简JavaScript代码
  • (第27天)Oracle 数据泵转换分区表
  • (二)fiber的基本认识
  • (理论篇)httpmoudle和httphandler一览
  • (六)vue-router+UI组件库
  • (论文阅读笔记)Network planning with deep reinforcement learning
  • (新)网络工程师考点串讲与真题详解
  • (一)使用Mybatis实现在student数据库中插入一个学生信息
  • (转)Sublime Text3配置Lua运行环境
  • (转)用.Net的File控件上传文件的解决方案
  • ****** 二十三 ******、软设笔记【数据库】-数据操作-常用关系操作、关系运算
  • ./configure,make,make install的作用(转)
  • .MSSQLSERVER 导入导出 命令集--堪称经典,值得借鉴!
  • .NET 2.0中新增的一些TryGet,TryParse等方法
  • .net 4.0发布后不能正常显示图片问题
  • .NET项目中存在多个web.config文件时的加载顺序
  • .NET中winform传递参数至Url并获得返回值或文件
  • @EnableConfigurationProperties注解使用
  • [ Linux ] git工具的基本使用(仓库的构建,提交)