I have asp:panel with some controls, the mark-up as below
<asp:panel id="panel1" runat="server">
<asp:Label runat="server" Text="aaaa"></asp:Label>
<asp:Label runat="server" Text="bbbb"></asp:Label>
<asp:Label runat="server" Text="cccc"></asp:Label>
<asp:TextBox runat="server" ID="txt1"></asp:TextBox>
<asp:TextBox runat="server" ID="txt2"></asp:TextBox>
<asp:ImageButton ID="ibtn1" runat="server"/>
<asp:ImageButton ID="ibtn2" runat="server"/>
</asp:panel>
Now I want to disable all the controls, but enabling ibtn1 and ibtn2
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
panel1.Enabled = False
End Sub
Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
ibtn1.Enabled = True
ibtn2.Enabled = True
End Sub
All of the controls are disabled, that’s great, but not for ibtn1 and ibtn 2.
Then, I have tried this method instead
Public Sub lDisableAllChildControls(ByRef p As WebControl)
For Each c As System.Web.UI.WebControls.WebControl In p.Controls
c.Enabled = False
'recurse
lDisableAllChildControls(c)
Next
End Sub
but it gave me this error:
Unable to cast object of type ‘System.Web.UI.LiteralControl’ to type
‘System.Web.UI.WebControls.WebControl’
Does anyone has any idea to make this work? Thanks!
you replace with Control, because your label is litteral