清除所有控件在ASP.NET页面与母版页 [英] Clear all controls in a ASP.NET page with a Master page

查看:186
本文介绍了清除所有控件在ASP.NET页面与母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从母版页。我想清楚在这个页面中使用波纹管的方法。这是行不通的。我尝试了所有的控件继承,如果母版页有一个asp.net页面。否则,其做工精细任何想法?

 私人无效ClearControls()
{
    的foreach(在Page.Controls控制C)
    {
        的foreach(在c.Controls控制CTRL)
        {
            如果(CTRL是文本框)
            {
                ((文本框)CTRL)。文本=的String.Empty;
            }
        }
    }
}


解决方案

试试这个:

 公共无效FindAllTextBox(控制CTRL)
{
    如果(CTRL!= NULL)
    {
        的foreach(在ctrl.Controls控制C)
        {
            如果(c是文本框)
                ((文本框)C)。文本=的String.Empty;
            FindAllTextBox(C);
        }
    }
}

例如:

 控制CTRL = this.FindControl(内容);
FindAllTextBox(CTRL);

I have a asp.net page which is inherited from a master page .I want to clear all controls in this page .I tried using the bellow method .This is not working if a master page is there. Otherwise its working fine any ideas?

private void ClearControls()
{
    foreach(Control c in Page.Controls)
    {
        foreach (Control ctrl in c.Controls)
        {
            if (ctrl is TextBox)
            {
                ((TextBox)ctrl).Text = string.Empty;
            }
        }
    }
} 

解决方案

try this:

public void FindAllTextBox(Control ctrl)
{
    if (ctrl != null)
    {
        foreach (Control c in ctrl.Controls)
        {
            if (c is TextBox)
                ((TextBox)c).Text = string.empty;
            FindAllTextBox(c);
        }
    }
}

Ex.:

Control ctrl = this.FindControl("content");
FindAllTextBox(ctrl);

这篇关于清除所有控件在ASP.NET页面与母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆