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
- If you are calling this function from different pages and then storing the state of page is very useful for example if you already disabled all the controls then there is no need to pass the page control to this method This can be easily done with storing the page state in session variable.
End Class
Join the conversation! Your thoughts help the community grow.