zoukankan      html  css  js  c++  java
  • .net通过一般处理程序模拟用户控件数据保持、Ispostback

    实现步骤:

    1.首先用StringBuiler将所需的表单等“画”出来,这里用StringBuider而不是直接用+号拼,这个问题不用解释吧呵呵

    2.通过将涉及到的文本框的数据动态的拼进去------实现用户控件数据保持

    3.在表单中添加一个隐藏域用来标示是否为回发过程

    应用一个简单的两个数相加求和的代码实现一下

    public class jsqHandler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/html";
    
            //声明三个整形变量
            int n1 = 0, n2 = 0, result = 0;
            bool ispostback = Convert.ToBoolean(context.Request.Form["IsPostBack"]);
            if (!ispostback)  //判断是否是第一次加载相当于aspx.cs中的IsPostBack
            {
                //分别获得数1和数2
                string sn1 = context.Request.Form["txtNum1"];
                string sn2 = context.Request.Form["txtNum2"];
                if (int.TryParse(sn1, out n1) && int.TryParse(sn2, out n2))
                {
                    result = n1 + n2;
                }
                context.Response.Write(result.ToString());
            }
            //绘制表单,其中有个隐藏域用于判断是否是回发过程
            StringBuilder sbHtml = new StringBuilder();
            sbHtml.Append("<html><head><title>简单计算器</title></head><body><form method = 'post'>")
                .Append("<input type = 'text' name = 'txtNum1' value = '" + n1.ToString() + "'/>")
                .Append("+<input type = 'text' name = 'txtNum2' value = '" + n2.ToString() + "'/>")
                .Append("=<input type = 'text' name = 'txtResult' value = '" + result.ToString() + "'/>")
                .Append("<input type = 'hidden' name = 'IsPostBack' value = 'false'/>")
                .Append("<br/><input type = 'submit' value = '计算'/>")
                .Append("</form></body>");
            context.Response.Write(sbHtml);
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
  • 相关阅读:
    java虚拟机字节码执行引擎
    java7 invokedynamic命令深入研究
    [转载]使用expect实现shell自动交互
    elasticsearch 聚合时 类型转换错误
    ES的关键端口
    CentOS6.5安装ganglia3.6
    Linux远程执行echo问题
    [转载]CentOS修改用户最大进程数
    elasticsearch新加入节点不能识别问题
    ssh免密码登录的注意事项
  • 原文地址:https://www.cnblogs.com/wlitsoft/p/2459853.html
Copyright © 2011-2022 走看看