有html和对应的一般处理程序ashx文件,单击按钮改变文本框的值

html中的代码:

    <form action="Once.ashx" method="get">
     
      <input type="hidden" name="isNullText" value="true" />
      <input type="text" name="price" value="0" />
      <input type="submit" value="提交" />

    </form>

.ashx中的代码:

public class Once : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
       
        string num=context.Request["price"];  //获得文本框的value值
        string isNullText = context.Request["isNullText"];  //得到表单的value值。"true"

        if (isNullText == "true") //如果相等是提交进来的并将将文本框里面的值加1,否则将文本里面的值负值为0
        {
            context.Response.Write("提交进入!");
         num=(int.Parse(num)+1).ToString();
        }
        else
        {
            context.Response.Write("直接进入!");
          num="0";
        }
       
        string fullPath = context.Server.MapPath("index.htm");    //获得html的路径将它给一个变量
        string htmlContext = System.IO.File.ReadAllText(fullPath);  //将这个路径负值给一个变量
        htmlContext = htmlContext.Replace("0",num);  //将文本框原有的值替换为改变后的数
        context.Response.Write(htmlContext);   //将整个html输出
       
        context.Response.Write("Hello World");
       
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

原文地址:https://www.cnblogs.com/qiqiBoKe/p/2791582.html