ASP.NET - Como recorrer los controles existentes

 
Vista:

Como recorrer los controles existentes

Publicado por Cristian (10 intervenciones) el 28/05/2007 15:39:02
Hola gente.

Quería saber como se puede hacer para optener los controles existentes (textbox,listbox etc) en una página o en un formview.
Mil gracias desde ya.
Cristian
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Como recorrer los controles existentes

Publicado por Cristian (1 intervención) el 14/02/2008 18:49:12
Esto es para una pagina; si lo haces para un formview, pasamelo. Saludos

string valorTextBox = "";

foreach (Control c in Page.Controls)
{
foreach (Control childc in c.Controls)
{
if (childc is TextBox)
{
valorTextBox += ((TextBox)childc).Text + ", ";
}
}
}
if (valorTextBox != "")
{
Label1.Text = valorTextBox;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Como recorrer los controles existentes

Publicado por asdf (1 intervención) el 02/07/2009 14:19:24
algun dia comenten algo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Como recorrer los controles existentes

Publicado por pablosguajardo (1 intervención) el 01/10/2009 23:03:08
eesta es la mejor: la hice yo, puede falllar...
private void colorear()
{
foreach (Control c in Page.Controls)
{
coloreaControl(c);
}
}

private void coloreaControl(Control c)
{
TextBox myTextBox;
foreach (Control childc in c.Controls)
{
if (childc is TextBox)
{
myTextBox = (TextBox)childc;
if (myTextBox.ReadOnly == true)
{
myTextBox.BackColor = System.Drawing.Color.FromArgb(230, 230, 230);
}
}
coloreaControl(childc);
}
}

llamamos recursivamente a coloreaControl a mi me anda joya.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Como recorrer los controles existentes

Publicado por Julio (2 intervenciones) el 20/12/2016 12:57:44
Se que paso harto tiempo pero aqui envio lo que use para recorrer todo
recorrer page, form, updatepanel, panel buscando textbox, label y buuton
lo use para modificar idioma de pagina web en asp.net
saludos


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Dim Cta As Control, Ctb As Control, Ctc As Control, Ctd As Control, Cte As Control
Dim strTipo As String
 
For Each Cta In xPage.Form.Controls 'recorre page
    For Each Ctb In Cta.Controls 'recorre forms
        strTipo = Ctb.GetType.ToString
        If TypeOf Ctb Is TextBox Then
            CType(Ctb, TextBox).Text = Idi(CType(Ctb, TextBox).Text)
        ElseIf TypeOf Ctb Is Label Then
            CType(Ctb, Label).Text = Idi(CType(Ctb, Label).Text)
        ElseIf TypeOf Ctb Is Button Then
            CType(Ctb, Button).Text = Idi(CType(Ctb, Button).Text)
        ElseIf strTipo = "System.Web.UI.UpdatePanel" Then 'recorre updatepanel
            For Each Ctc In Ctb.Controls
                strTipo = Ctc.GetType.ToString
                If TypeOf Ctc Is TextBox Then
                    CType(Ctc, TextBox).Text = Idi(CType(Ctc, TextBox).Text)
                ElseIf TypeOf Ctc Is Label Then
                    CType(Ctc, Label).Text = Idi(CType(Ctc, Label).Text)
                ElseIf TypeOf Ctc Is Button Then
                    CType(Ctc, Button).Text = Idi(CType(Ctc, Button).Text)
                End If
 
                For Each Ctd In Ctc.Controls 'recorre otros
                    strTipo = Ctd.GetType.ToString
                    If TypeOf Ctd Is TextBox Then
                        CType(Ctd, TextBox).Text = Idi(CType(Ctd, TextBox).Text)
                    End If
                    If TypeOf Ctd Is Label Then
                        CType(Ctd, Label).Text = Idi(CType(Ctd, Label).Text)
                    End If
                    If TypeOf Ctd Is Button Then
                        CType(Ctd, Button).Text = Idi(CType(Ctd, Button).Text)
                    End If
 
                    If TypeOf Ctd Is Panel Then 'button
                        For Each Cte In Ctd.Controls
                            strTipo = Cte.GetType.ToString
                            If TypeOf Cte Is TextBox Then
                                CType(Cte, TextBox).Text = Idi(CType(Cte, TextBox).Text)
                            End If
                            If TypeOf Cte Is Label Then
                                CType(Cte, Label).Text = Idi(CType(Cte, Label).Text)
                            End If
                            If TypeOf Cte Is Button Then
                                CType(Cte, Button).Text = Idi(CType(Cte, Button).Text)
                            End If
                        Next
                    End If
                Next
            Next
        End If
    Next
Next
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Como recorrer los controles existentes

Publicado por Fernando (1 intervención) el 29/07/2017 14:51:51
Hola gracias por tu aporte.

Te quería consultar :

que es ldi "Porque no esta declarada"

ej:

Idi(CType(Cte, TextBox).Text)


muchas gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Como recorrer los controles existentes

Publicado por julio (2 intervenciones) el 30/07/2017 01:47:41
Es para lo que lo use me permite personalizar los textos de label en cualquier idioma
pero no lo puse porque no tiene nada que ver con lo que preguntaban, lo que importa es como recorrer los controles en la pagina
saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar