/WebSiteTest中新建
AddCalc1.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<form action="AddCalc1.ashx">
<input type="hidden" name="huilaile" value="yes" />
<input type="text" name="num1" value="@num1" />+<input type="text" name="num2" value="@num2" /><input type="submit" value="=" />
<input type="text" value="@result" readonly="readonly" />
</form>
</body>
</html>
-------------------------------------------------------
<%@ WebHandler Language="C#" Class="AddCalc1" %>

using System;
using System.Web;

public class AddCalc1 : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        string huilaila = context.Request["huilaile"];
     //   context.Response.Write("Hello World");
        //如果想保存,前两个加数的值,需要添加变量
        string num1 = "";
        string num2 = "";
            
   
        string result = "";
        if (huilaila=="yes") {
              num1=context.Request["num1"];
              num2=context.Request["num2"];
             result = Convert.ToString (Convert.ToInt32(num1) + Convert.ToInt32(num2));
            context.Response.Write("<script type='text/javascript'>alert('Hello everyOne Im Credream')</script>");
        }
        string html文件模板全路径 = context.Server.MapPath("AddCalc1.htm");//得到文件的全路径
        string content = System.IO.File.ReadAllText(html文件模板全路径);
        //替换前两个单元格的值,保存原有的值
        //这里每写一次:content就是一个html页面,但是由于浏览器的容错性,所以不会显示出错
       // context.Response.Write(content);
        //这里的context.Response.Write(content);,可以看出来每一步,它是如何替换的
        content = content.Replace("@num1", num1);
       // context.Response.Write(content);
        content = content.Replace("@num2", num2);
      //  context.Response.Write(content);
        content = content.Replace("@result", result);
        context.Response.Write(content);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}
-------------------------------
生成的下面的html代码很明显是错误的,但是显示出来并没有问题,提现了浏览器的容错性:
先看看浏览器的容错性:

<script type='text/javascript'>alert('Hello everyOne Im Credream')</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<form action="AddCalc1.ashx">
<input type="hidden" name="huilaile" value="yes" />
<input type="text" name="num1" value="1" />+<input type="text" name="num2" value="1" /><input type="submit" value="=" />
<input type="text" value="2" readonly="readonly" />
</form>
</body>
</html>

ASP.Net学习笔记010--加法计算器相关推荐

  1. ASP.Net学习笔记001--ASP.Net简介1

    ASP.Net学习笔记001--ASP.Net简介1 2016/1/10 以前写的课程都没有附上源码,很抱歉! 课程中的源码可以加qq索要:1606841559 也可以自己下载: ASP.Net学习笔 ...

  2. ASP.Net学习笔记015--ASP.Net中使用Cookie

    ASP.Net学习笔记015--ASP.Net中使用Cookie 表单数据欺骗: 原理跟收到欺骗短信一样,移动信号塔[基站],伪装的移动信号塔会屏蔽移动信号,并且 在信号范围内的手机会自动切换为接收伪 ...

  3. ASP.Net学习笔记014--ViewState初探3

    ASP.Net学习笔记014--ViewState初探3 为什么禁用了viewstate,还能修改label2的值 因为:viewstate只是记录label2的值,并不影响给label2进行设置 - ...

  4. ASP.Net学习笔记013--ViewState初探2

    ASP.Net学习笔记013--ViewState初探2 上课讲的viewstate,由于需要跟后台服务器进行传值,需要封装很多隐藏列,比如100条数据,就会有100个viewstate 如果用在一些 ...

  5. ASP.Net学习笔记008--ASP.Net揭秘之Input版自增补充说明

    以前写的课程都没有附上源码,很抱歉! ASP.Net学习笔记007ASP.Net Input版自增.zip http://credream.7958.com/down_20155694.html 1. ...

  6. ASP.Net学习笔记007--ASP.Net Input版自增

    2016/1/18 以前写的课程都没有附上源码,很抱歉! 课程中的源码可以加qq索要:1606841559 技术交流qq1群:251572072 技术交流qq2群:170933152 也可以自己下载: ...

  7. ASP.Net学习笔记006--Get和Post的区别

    以前写的课程都没有附上源码,很抱歉! 课程中的源码可以加qq索要:1606841559 技术交流qq1群:251572072 技术交流qq2群:170933152 也可以自己下载: ASP.Net学习 ...

  8. ASP.Net学习笔记005--ASP.Net的IsPostBack揭秘

    以前写的课程都没有附上源码,很抱歉! 课程中的源码可以加qq索要:1606841559 技术交流qq1群:251572072 技术交流qq2群:170933152 也可以自己下载: ASP.Net学习 ...

  9. ASP.Net学习笔记004--基于ashx方式的ASP.Net开发1

    以前写的课程都没有附上源码,很抱歉! 课程中的源码可以加qq索要:1606841559 技术交流qq1群:251572072 技术交流qq2群:170933152 也可以自己下载: ASP.Net学习 ...

最新文章

  1. GA(遗传算法)的Matlab程序原理(from:六分之一工作室)
  2. 外文翻译 《How we decide》赛场上的四分卫
  3. JAVA常见错误处理方法 和 JVM内存结构
  4. java基础之多态的详细解释_JAVA基础之多态
  5. 红帽 jboss_红帽峰会2015所需的JBoss BPM内容指南
  6. bzoj1222: [HNOI2001]产品加工
  7. 05 切片、迭代、列表生成
  8. python里面的tuple与list对比
  9. java编译sql存过_SQL SERVER 临时表导致存储过程重编译(recompile)的一些探讨
  10. 客户端(https)与服务器交互过程
  11. 如何在Mac上使用触控栏?
  12. Mysql基础系列(一)
  13. 如果我是决策者,我会决策做CPU吗?
  14. 7.2.5 dps 测试软件,《魔兽世界》7.2.5兽王猎DPS改动测试
  15. 阮工的单片机编程经验集:如何做稳定单片机程序与上位机程序防卡顿,js等经验;阮丁远于20221111
  16. ESP8266|ESP8266入门教程-AT指令视频教程(基于ESP-01S/ESP8266-01S)
  17. php mysql 嵌套查询_MYSQL数据库MySQL嵌套查询实例详解
  18. 阿里云快速搭建网站教程
  19. HMI-66-【MeterDisplay for Arm Linux】液晶仪表Arm Linxu迁移
  20. 佩戴安全帽数据集使用说明和下载

热门文章

  1. 【Machine Learning 一】监督学习与无监督学习
  2. ubuntu16.04卸载firefox,然后再次安装firefox
  3. 【转】深度解析 Qt 中动态链接库
  4. NSRegularExpression iOS自带的正则表达式
  5. mysqld或mysqld_safe启动时必须放在第一位的参数(first argument)
  6. LNMP Keepalived Haproxy 笔记
  7. chrome 非安全模式解决开发跨域问题
  8. CentOS 7 安装VirtualBox
  9. Spark MLib 数据类型
  10. LoadRunner10自带的WEBTOURS,无法显示Flights页面问题解决办法