简单的asp 计算程序

版本一:

html页面

<!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="go.ashx" method="post">
      <input type="text" name="txtnum1" value="0" />
      <input type="text" name="txtnum2" value="0" />
      <input type="text" name="txtnum3" value="0" />
      <input type="submit" value="提交" />
     </form>


</body>
</html>

一般处理程序

<%@ WebHandler Language="C#" Class="go" %>

using System;
using System.Web;

public class go : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {

        string strnum1 = context.Request.Form["txtnum1"];
        string strnum2 = context.Request.Form["txtnum2"];

        int x = 0,y=0,z=0;
        if (!string.IsNullOrEmpty(strnum1) && !string.IsNullOrEmpty(strnum2))
        {
            if (int.TryParse(strnum1, out x) && int.TryParse(strnum2, out y))
            {
                z = x + y;
            }
        }

        System.Text.StringBuilder sbHtml = new System.Text.StringBuilder();

        sbHtml.Append("<html ><head><title></title></head>");
        sbHtml.Append("<body><form  action='' method='post'>");
        sbHtml.Append("<input type='text name='txtnum1' value='"+x.ToString()+"'/>+<input type='text' name='txtnum2' value='"+y.ToString()+"'/>");
        sbHtml.Append(""+"<input type='text' name='txtnum3' value='"+z.ToString()+"' />+<input type='submit' value='提交' />");
        sbHtml.Append("</form></body></html>");

        
        //context.Response.ContentType = "text/plain";
        context.Response.Write(sbHtml.ToString());
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

版本二:

模版占位符:

html

<!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="go.ashx" method="post">
      <input type="text" name="txtnum1" value='{num1}' />
      <input type="text" name="txtnum2" value='{num2}' />
      <input type="text" name="txtnum3" value='{num3}' />
      <input type="submit" value="提交" />
     </form>


</body>
</html>

一般处理程序

<%@ WebHandler Language="C#" Class="go" %>

using System;
using System.Web;

public class go : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/html";
        string path = context.Server.MapPath("computer.htm");
        string sbHtml = System.IO.File.ReadAllText(path);
        
        string strnum1 = context.Request.Form["txtnum1"];
        string strnum2 = context.Request.Form["txtnum2"];

        int x = 0,y=0,z=0;
        if (!string.IsNullOrEmpty(strnum1) && !string.IsNullOrEmpty(strnum2))
        {
            if (int.TryParse(strnum1, out x) && int.TryParse(strnum2, out y))
            {
                z = x + y;
            }
        }

        sbHtml= sbHtml.Replace("{num1}",x.ToString()).Replace("{num2}", y.ToString()).Replace("{num3}", z.ToString());
        //context.Response.ContentType = "text/plain";
        context.Response.Write(sbHtml);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值