自增按钮ashx页面

<%@ WebHandler Language="C#" class="add"  %>

using System;
using System.Web;
using System.IO;

public class add : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        int n = 0;
        //第一步,读取静态页面.
        string path = context.Request.MapPath("01add.htm");
        string html = File.ReadAllText(path);
        //第二步,判断是否首次加载
        string vs = context.Request.Form["_viewstate"];
        if (!string.IsNullOrEmpty(vs))
        {
            string num = context.Request.Form["hdNum"];
            n = int.Parse(num);
            n++;
            //把hdNum的value@num替换成n.
            html = html.Replace("@num",n.ToString());
        }
        else
        {
            //把hdNum的value@num替换成0.
            html = html.Replace("@num", "0");
        }
        //第三步,输出页面.
        context.Response.Write(html);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

posted @ 2013-08-10 10:14  nqsan  阅读(249)  评论(0编辑  收藏  举报