时间:2021-07-01 10:21:17 帮助过:27人阅读
代码如下:
<form action="数值自增.ashx" method="post"> <input type="hidden" name="_viewstate" value="a" /> <input type="hidden" name="_p" value="@n" /> <!-- <input name="txt" type="text" value="@value" />--> <p>@n</p> <input type="submit" value="click" /> </form>
使用一般处理程序实现
数值自增.ashx
代码如下:
int n = 0;
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
string path = context.Request.MapPath("数值自增.htm");
string html = System.IO.File.ReadAllText(path);
//判断页面是否是第一次加载
string viewstate = context.Request.Form["_viewstate"];
if (!string.IsNullOrEmpty(viewstate))
{
//点击按钮 post
//获取隐藏域的值
string s = context.Request.Form["_p"];
if (int.TryParse(s, out n))
{
n++;
html = html.Replace("@n",n.ToString());
}
}
else
{
//页面首次加载,给p和p对应的隐藏域赋值
html = html.Replace("@n", n.ToString());
}
context.Response.Write(html);
}以上就是详解html中隐藏域hidden的作用介绍及使用示例代码的详细内容,更多请关注Gxl网其它相关文章!