我们怎样才能在一个函数中找到所有文本框控件 [英] how can we find all textbox control in one function

查看:78
本文介绍了我们怎样才能在一个函数中找到所有文本框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个函数中找到所有文本框控件。

我怎么能这样做以及我必须在page_load或任何其他事件中调用该函数?

i want to find all textbox control in one function.
how can i do this and where i have to call that function, in page_load or in any other event??

推荐答案

它将在asp.net中运行

it will work in asp.net
public partial class _Default : System.Web.UI.Page
   {
      
       public List<TextBox> ListOfTextBoxes = new List<TextBox>();
       protected void Page_Load(object sender, EventArgs e)
       {
           // after execution this line
           FindTextBoxes(Page, ListOfTextBoxes);
           //ListOfTextBoxes will be populated with all text boxes with in the page.

       }


       private void FindTextBoxes(Control Parent, List<TextBox> ListOfTextBoxes)
       {
           foreach (Control c in Parent.Controls) {
               // if c is a parent control like panel
               if (c.HasControls())
               {
                   // search all control inside the panel
                   FindTextBoxes(c, ListOfTextBoxes);
               }
               else {
                   if (c is TextBox)
                   {
                       // if c is type of textbox then put it into the list
                       ListOfTextBoxes.Add(c as TextBox);
                   }
               }
           }
       }
   }


这篇关于我们怎样才能在一个函数中找到所有文本框控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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