I need to loop through all my textboxes and lables to set the visible="False" when IsPostBack = True. I tried this:<BR>Sub Page_Load(Sender AS Object, E AS EventArgs)<BR> If IsPostBack Then<BR> Dim ctrl as Control<BR> For each ctrl in Controls<BR> ctrl.Visible = false<BR> Next<BR> End If <BR>End Sub<BR><BR>But then everything on my page disappeared! Is there a way I can say that all my textboxes (and/or labels) should have visible set to False without loosing everything else on my page?If you selectively specify for each textbox/listbox a specified ID property, like making all textbox's ID property start with "txt", like "txtName", "txtAge", etc., then you could, in your loop above, check to see if the ID's first three letters are "txt" and, if so, hide it.<BR><BR>I'm almost certain there's a better way, but I don't have the time right now to root through the docs. Best of luck, let me know if this approach works for you...
It would solve my problem if I could do it like that, but I can't get a hold of the ID.. Do you see where the problem is?<BR>Dim myControl AS Control<BR>For Each myControl in Page.Controls<BR> Response.Write(myControl.ID & "<BR>")<BR>NextYou have to find the System.Web.UI.HtmlControls.HtmlForm with the first loop in order to find System.Web.UI.WebControls.TextBox with a second loop. Like this:<BR>Dim ctrCtrl AS Control<BR>Dim ctrControl AS Control<BR>For Each ctrCtrl IN Page.Controls <BR> If ctrCtrl.UniqueID.ToString() = "frmRegisterArticle" Then <BR> For Each ctrControl IN ctrCtrl.Controls<BR> If ctrControl.GetType().ToString() = "System.Web.UI.WebControls.TextBox" Then<BR> ctrControl.Visible = False<BR> End If<BR> Next<BR> End If<BR>Next<BR>
