是一个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;
}
}
}
}
点击按钮为啥不会自增
这个判断有问题,因为他始终是null,他没有value值
哦哦,原来没有加value值,谢谢了