ASP.NET - Recorrer WebControl

 
Vista:

Recorrer WebControl

Publicado por nerea (1 intervención) el 20/04/2010 17:58:10
Hola buenas!!

Mi problema es que nos e como puedo recorrer los WebControls que una página .aspx pueda tener.
He intentado utilizando Me.controls pero no me aparecen los controles que yo tengo definidos.
Por ejemplo, yo tengo definidos estos controles, y quiero poder obtener todos los controles <asp> para poder cargar en ellos algunos valores.

<table class="tDatos">
<tr>
<td><asp:Label ID ="lblD_TORNEADO" CssClass="titulo3" runat="server" Text="Dimetro torneado"></asp:Label></td>
<td><asp:DropDownList ID="ctlD_TORNEADO" runat="server" CssClass="drpSeleccion"></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Label ID ="lblH_MAX_TORNEADO" CssClass="titulo3" runat="server" Text="Altura mxima de torneado"></asp:Label></td>
<td><asp:DropDownList ID="ctlH_MAX_TORNEADO" runat="server" CssClass="drpSeleccion"></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Label ID ="lblCURSO_TRAV" CssClass="titulo3" runat="server" Text="Curso Travesao"></asp:Label></td>
<td><asp:DropDownList ID="ctlCURSO_TRAV" CssClass="drpSeleccion" runat="server"></asp:DropDownList></td>
</tr>
</table>

Mi codigo:
ForEach miControl In Me.Controls
'Verificamos si el control es un TextBox
If (TypeOf (hijos) Is TextBox) Then
'CType(miControl, TextBox).Text = ""
End If
If (TypeOf (hijos) Is DropDownList) Then
'CType(miControl, DropDownList).SelectedIndex = 0
'cargarCombo(nombreVariable, master)
'SortDropDown(ctl.ID, master)
End If
If (TypeOf (hijos) Is RadioButtonList) Then
For i = 0 To CType(miControl, RadioButtonList).Items.Count - 1'CType(miControl, RadioButtonList).Items(i).Selected = False
Next
End If
If (TypeOf (hijos) Is CheckBoxList) Then
For i = 0 To CType(miControl, CheckBoxList).Items.Count - 1'CType(miControl, CheckBoxList).Items(i).Selected = False
Next
End If
If (TypeOf (hijos) Is DataGrid) Then
'CType(miControl, DataGrid).Controls.Clear()
End If
Next

Espero que me podais ayudar
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:Recorrer WebControl

Publicado por Santos Pairazamán (54 intervenciones) el 24/04/2010 00:59:38
Puede utilizar

Dim myCtrl As Control
si esta en la master
myCtrl = pagina.Master.FindControl("Nombre del Control")

Si esta en otra pagina
myCtrl = pagina.Master.FindControl("Main").FindControl("Nombre del Control")

luego cambias las propiedades q desees
If (Not myCtrl Is Nothing) Then
myCtrl.Visible = True
End If

Esto lo utilizo en un procedimiento donde pagina es donde se encuentre (Me.Page).

Espero t d una idea.

Salu2.
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