Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8446593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:58:31+00:00 2026-06-10T09:58:31+00:00

I have asp:panel with some controls, the mark-up as below <asp:panel id=panel1 runat=server> <asp:Label

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:58:32+00:00Added an answer on June 10, 2026 at 9:58 am

    you replace with Control, because your label is litteral

     For Each c As System.Web.UI.Control.Control In p.Controls
    
     Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datalist inside the panel <asp:Panel ID=Panel1 runat=server ScrollBars=Vertical> <asp:DataList ID=DataList1 runat=server
In my page I have a login control: <asp:Login ID=EMSLogin runat=server OnAuthenticate=EMSLogin_Authenticate> <LayoutTemplate> <asp:Panel
I have 2 asp.net textboxes in an update panel. Both textbox controls have some
I have a ASP updatepanel, within that panel I have some controls which got
I have this panel... <asp:Panel ID=panSumarios runat=server style=border:0px solid red;width:100% ViewStateMode=Enabled></asp:Panel> ...inside a div
I have an Asp.Net 4.0 website/control interface that uses an update panel and some
I have this following code, here CssClass is of the String type. <asp:Panel ID=Panel1
I have a asp:panel on the root and a lot of controls inside. When
Within an asp.net webform I have some jquery that controls the positioning of elements
I have a Panel control that contains some control such as text boxes.I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.