是一个div实现自增的问题<form action="divSelfPlus.ashx" method="post">
  <div>{num}</div>
 <input type="submit" value="增加" />
  <input type="hidden" name="ispostback" />
  <input type="hidden" name="txtNum" value="{hidnum}" />
  </form>
ashx文件using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;namespace WebApplication1
{
    /// <summary>
    /// divSelfPlus 的摘要说明
    /// </summary>
    public class divSelfPlus : IHttpHandler
    {        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            int num = 0;
            if (!string.IsNullOrEmpty(context.Request.Form["ispostback"]))
            {
                string strNum = context.Request.Form["txtNum"];
                int.TryParse(strNum, out num);
                num++;
            }
            string strPhyPath = context.Server.MapPath("divSelfPlus.htm");
            string strFile = System.IO.File.ReadAllText(strPhyPath);
            strFile = strFile.Replace("{num}", num.ToString()).Replace("{hidnum}", num.ToString());
            context.Response.Write(strFile);
        }        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
点击按钮为啥不会自增

解决方案 »

  1.   

    你第一次请求之后已经把{num}和{hidnum}替换成数字了,第二次就替换不了了吧??
      

  2.   

    string.IsNullOrEmpty(context.Request.Form["ispostback"])
    这个判断有问题,因为他始终是null,他没有value值
      

  3.   

    你随便给他<input type="hidden" name="ispostback" />添加个value就可以了
      

  4.   

    那要怎样改,我也想是应该在HTML页面改,但不知道怎样改
      

  5.   


    哦哦,原来没有加value值,谢谢了
      

  6.   

    用正则吧!把<div>{num}</div>设个ID,然后用正则去替换里面的内容。