W
Wayne Wengert
I have an asp page with several pairs of labels and textboxes. If the user
takes a specific action, I want to hide all text boxes and labels with IDs
of "Label4" through "Label13". I am using the subroutine below to try to
accomplish this but only the txt boxes age getting hidden? As you can see in
the code, when the loop to hide the labels did not work I manually coded
that and the labels are still visible?
What did I overlook?
====================== Code ======================
Private Sub HideDataFields()
Dim frmCntrl As Control
Dim cntrl As Control
Dim txtbox As System.Web.UI.HtmlControls.HtmlInputText
frmCntrl = Page.FindControl("Form1")
For Each cntrl In frmCntrl.Controls
If TypeOf cntrl Is System.Web.UI.HtmlControls.HtmlInputText Then
'txtbox = cntrl
cntrl.Visible = False
'Response.Write(txtbox.ID & ":" & txtbox.Value & ":" & txtbox.Name & "<br>")
End If
Next
Dim jj As Integer
For Each cntrl In frmCntrl.Controls
For jj = 4 To 13
If cntrl.ID = "Label" + jj Then
cntrl.Visible = False
End If
Next
Next
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
Label13.Visible = False
Panel2.Visible = False
End Sub
takes a specific action, I want to hide all text boxes and labels with IDs
of "Label4" through "Label13". I am using the subroutine below to try to
accomplish this but only the txt boxes age getting hidden? As you can see in
the code, when the loop to hide the labels did not work I manually coded
that and the labels are still visible?
What did I overlook?
====================== Code ======================
Private Sub HideDataFields()
Dim frmCntrl As Control
Dim cntrl As Control
Dim txtbox As System.Web.UI.HtmlControls.HtmlInputText
frmCntrl = Page.FindControl("Form1")
For Each cntrl In frmCntrl.Controls
If TypeOf cntrl Is System.Web.UI.HtmlControls.HtmlInputText Then
'txtbox = cntrl
cntrl.Visible = False
'Response.Write(txtbox.ID & ":" & txtbox.Value & ":" & txtbox.Name & "<br>")
End If
Next
Dim jj As Integer
For Each cntrl In frmCntrl.Controls
For jj = 4 To 13
If cntrl.ID = "Label" + jj Then
cntrl.Visible = False
End If
Next
Next
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
Label13.Visible = False
Panel2.Visible = False
End Sub