foreach(Control control in this.Controls)
{
if(contorl is TextBox)
{
.....
}
}
不过因为Control可能会有Child Control,所以你要在这边做递归.

解决方案 »

  1.   

    foreach(Control ctrls in Page.controls)
    {
        if (ctrl is TextBox)
        {
         ....
        }
    }
    你看看可不可以
      

  2.   

    楼上的contorl和偶的ctrl应该改为control和ctrls
      

  3.   

    foreach (Control control in this.Controls[1].Controls)
    {
      if (control is TextBox)
      {
       ...
       }
    }
      

  4.   

    foreach (Control control in this.Controls[1].Controls)
    {
      if (control is TextBox)
      {
       ...
       }
    }记住一定是Controls[1] 才是窗体上所有控件的集合
      

  5.   

    private void VisitSubControls( Control parentCtrl )
    {

    SetCultrueInfo( parentCtrl );
    SetCssClassInfo( parentCtrl ); if ( !parentCtrl.HasControls() ) return; foreach ( Control ctrl in parentCtrl.Controls )
    {
    VisitSubControls( ctrl );
    }
    } private void SetCultrueInfo( Control ctrl )
    {
    string strValue = ""; try
    {
    if ( ctrl is Button )
    {
    if ( ctrl is ButtonBase )
    {
    ButtonBase curCtrlBase = ( ButtonBase )ctrl;
    strValue = rmResxMan.GetString( PageName + "."+curCtrlBase.ID+".AlertText" );
    if ( strValue != null && strValue.Trim().Length > 0 ) curCtrlBase.AlertText = strValue;
    strValue = rmResxMan.GetString( PageName + "."+curCtrlBase.ID+".ConfirmText" );
    if ( strValue != null && strValue.Trim().Length > 0 ) curCtrlBase.ConfirmText = strValue;
    if ( isRecordCtrlText )
    {
    RecordCtrlText( dsWebFormCtrl, PageName, curCtrlBase.ID+".AlertText" ,curCtrlBase.AlertText );
    RecordCtrlText( dsWebFormCtrl, PageName, curCtrlBase.ID+".ConfirmText" ,curCtrlBase.ConfirmText );
    }
    }
    Button curCtrl = ( Button )ctrl;
    strValue = rmResxMan.GetString( PageName + "."+curCtrl.ID+".Text" );
    if ( strValue != null && strValue.Trim().Length > 0 ) curCtrl.Text = strValue;
    strValue = rmResxMan.GetString( PageName + "."+curCtrl.ID+".ToolTip" );
    if ( strValue != null && strValue.Trim().Length > 0 ) curCtrl.ToolTip = strValue;
    if ( isRecordCtrlText )
    {
    RecordCtrlText( dsWebFormCtrl, PageName, curCtrl.ID+".Text" ,curCtrl.Text );
    RecordCtrlText( dsWebFormCtrl, PageName, curCtrl.ID+".ToolTip" ,curCtrl.ToolTip );
    }
    }
    else if ( ctrl is CheckBox )
    {
    CheckBox curCtrl = ( CheckBox )ctrl;
    strValue = rmResxMan.GetString( PageName + "."+curCtrl.ID+".Text" );
    if ( strValue != null && strValue.Trim().Length > 0 ) curCtrl.Text = strValue;
    strValue = rmResxMan.GetString( PageName + "."+curCtrl.ID+".ToolTip" );
    if ( strValue != null && strValue.Trim().Length > 0 ) curCtrl.ToolTip = strValue;
    if ( isRecordCtrlText )
    {
    RecordCtrlText( dsWebFormCtrl, PageName, curCtrl.ID+".Text" ,curCtrl.Text );
    RecordCtrlText( dsWebFormCtrl, PageName, curCtrl.ID+".ToolTip" ,curCtrl.ToolTip );
    }
    }
    else if ( ctrl is DataGrid )
    {
                                }
    ... ...
    else if ( ctrl is TextBox )
    {
    TextBox curCtrl = ( TextBox )ctrl;
    strValue = rmResxMan.GetString( PageName + "."+curCtrl.ID+".Text" );
    if ( strValue != null && strValue.Trim().Length > 0 ) curCtrl.Text = strValue;
    strValue = rmResxMan.GetString( PageName + "."+curCtrl.ID+".ToolTip" );
    if ( strValue != null && strValue.Trim().Length > 0 ) curCtrl.ToolTip = strValue;
    if ( isRecordCtrlText )
    {
    RecordCtrlText( dsWebFormCtrl, PageName, curCtrl.ID+".Text" ,curCtrl.Text );
    RecordCtrlText( dsWebFormCtrl, PageName, curCtrl.ID+".ToolTip" ,curCtrl.ToolTip );
    }
    } }
    catch( Exception )
    {
    } return;
    }
      

  6.   

    VisitSubControls( this.Page );
      

  7.   

    arding123(阿拉丁)
    我还没试不过相信你
      

  8.   

    需要跟排版结合起来...有的是包含控件,有的不是,要考虑包含控件是否用HTML的还是WEBCONTROL...再用递归方法来遍历..
      

  9.   

    goody9807() 
    正确!