zoukankan      html  css  js  c++  java
  • 遍历页面上所有TextBox,并赋值为String.Empty

    //不含母板页
    foreach (System.Web.UI.Control txtobj in this.Page.Controls)
     
    {
        if (txtobj.GetType().Name .Equals("TextBox"))
        {
           // ((TextBox)txtobj).Text = String.Empty;//这是第一种方法赋值,第二种在下面
            TextBox tb = new TextBox();
             tb = (TextBox)this.FindControl(txtobj.ID);
     
             tb.Text = String.Empty;
        }
    }
     

    包含母板页


    //套用母版页的页面遍历TextBox控件的方法,其他控件类似
     
    foreach (Control cp in Page.Controls)   
    {   
           foreach (System.Web.UI.Control ct in cp.Controls)   
           {  
                if (ct is HtmlForm)   
                {   
                      foreach (Control con in ct.Controls)  
                      {   
                          foreach (Control c in con.Controls)  
                          {  
                              if (c is TextBox)  
                              {  
                                  (c as TextBox).Text = String.Empty;  
                              }  
                          }   
                      }   
                 }   
           }   
    }

     

  • 相关阅读:
    Hibernate事务代码规范写法
    关于hibernate插入数据时的乱码问题
    搭建hibernate环境(重点)
    接口测试概念以及用postman进行接口测试
    Atom编辑器之加快React开发的插件汇总
    如何搭建git服务器
    phpstorm 配置 xdebug调试工具
    linux 获取指定行范围文本内容
    odoo 创建一个qweb
    linux nohup 使用
  • 原文地址:https://www.cnblogs.com/dashi/p/4034625.html
Copyright © 2011-2022 走看看