There might be situations where you want to retrieve controls that are present in a web page and process them. In that case this article can be very use. Basically a web page is a container for all controls and for retrieving all controls we need to traverse the control tree. So for this this program can be used to disable all form controls at runtime

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
disableControls(Me.Page)

End Sub
Public Sub
disableControls(ByVal controltree As Control)
For Each tempcontrol As Control In controltree.Controls
If TypeOf tempcontrol Is TextBox Then
CType
(tempcontrol, TextBox).Enabled = False
Continue For
ElseIf TypeOf
tempcontrol Is Label Then
CType
(tempcontrol, Label).Enabled = False
Continue For
ElseIf TypeOf
tempcontrol Is Button Then
CType
(tempcontrol, Button).Enabled = False
Continue For
ElseIf
tempcontrol.Controls.Count > 0 Then
disableControls(tempcontrol)
End If
Next
End Sub

Before using this code there are some performance issues


End Class