2016/1/18
技术交流qq1群:251572072
技术交流qq2群:170933152
也可以自己下载:
ASP.Net学习笔记007ASP.Net Input版自增.zip
http://credream.7958.com/down_20155694.html
这节由于非常简单,仅仅用一个例子来说明:
用程序实现,数字自动加1
---------------------------
新建:/WebSiteTest
IncValue.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="IncValue.ashx">
<input type="hidden" name="ispostback" value="true" />
<input type="text" name="number" value="@value" />
<input type="submit" value="自增" />
</form>
</body>
</html>
----------------------------------------------------------
IncValue.ashx
<%@ WebHandler Language="C#" Class="IncValue" %>
using System;
using System.Web;
public class IncValue : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
string ispostback = context.Request["ispostback"];
string number = context.Request["number"];
//通过表单提交的都是string类型的
if (ispostback == "true")//说明点击了也没的自增按钮
{
int i = Convert.ToInt32(number);
i++;
number = i.ToString();
}
else {//第一次进入,值为0
number = "0";
}
//context.Response.Write(number);
string fullpath = context.Server.MapPath("IncValue.htm");
string content = System.IO.File.ReadAllText(fullpath);
content= content.Replace("@value", number);
context.Response.Write(content);
//context.Response.Write("你好");
}
public bool IsReusable {
get {
return false;
}
}
}
-------------------------------------------