Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Child Controls Showing as Null

Child Controls Showing as Null

Scheduled Pinned Locked Moved ASP.NET
helptutorialdata-structuresquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Muir
    wrote on last edited by
    #1

    Hi All, I am currently fighting with a problem with regards to finding controls within ContentPlaceHolders. The scenario is that I want to be able to set the class on a control with a specified ID, which is on one of the Master pages which the page inherits from. There is no limit to how many levels up the tree the control can be, and the code searches recursively until the root master page. This part I have working. :) The issue that I am having is that I can only find a control if it is on the root master page.(I.e. not within a ContentPlaceHolder). If the control is on any other page then FindControl() does not find the control. In this example, the control would only be found if on DefaultMaster. DefaultMaster --> SectionMaster --> PageMaster --> Page.aspx I have investigated further, and found that controls within a Content control are being retured as null, although they clearly exist. Obviously as these are null, FindControl can't find them. I have tried attempting to find a control within the content section also, but I have the same issue. Unfortunately, if you take the above example, then my control would be in SectionMaster, as I dont have access to the root master page. (I'm using Umbraco currently for this project.) Does anyone have any suggestions to how to get these values from content controls? Thanks in advance, DM.

    E 1 Reply Last reply
    0
    • D David Muir

      Hi All, I am currently fighting with a problem with regards to finding controls within ContentPlaceHolders. The scenario is that I want to be able to set the class on a control with a specified ID, which is on one of the Master pages which the page inherits from. There is no limit to how many levels up the tree the control can be, and the code searches recursively until the root master page. This part I have working. :) The issue that I am having is that I can only find a control if it is on the root master page.(I.e. not within a ContentPlaceHolder). If the control is on any other page then FindControl() does not find the control. In this example, the control would only be found if on DefaultMaster. DefaultMaster --> SectionMaster --> PageMaster --> Page.aspx I have investigated further, and found that controls within a Content control are being retured as null, although they clearly exist. Obviously as these are null, FindControl can't find them. I have tried attempting to find a control within the content section also, but I have the same issue. Unfortunately, if you take the above example, then my control would be in SectionMaster, as I dont have access to the root master page. (I'm using Umbraco currently for this project.) Does anyone have any suggestions to how to get these values from content controls? Thanks in advance, DM.

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      What event in the Page Lifecycle is your code running? Child controls generally will not be available until after the load event fires for said control. That said, code is not supposed to access controls up the hierarchy only below it. If you need to access something from your parent container, the parent should provide a method to perform said action. Otherwise you introduce unmanageable dependencies.

      Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

      D 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        What event in the Page Lifecycle is your code running? Child controls generally will not be available until after the load event fires for said control. That said, code is not supposed to access controls up the hierarchy only below it. If you need to access something from your parent container, the parent should provide a method to perform said action. Otherwise you introduce unmanageable dependencies.

        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

        D Offline
        D Offline
        David Muir
        wrote on last edited by
        #3

        I'm using the Page_Load event on the User Control. What I do at first is a FindControl() on the current control, if its not found, it does a a FindControl() on the page which the control is on. If thats not found, it looks at the Master for that Page and continues to do this until the control is found, or it is the root masterpage. It only seems to find controls outwith the content place hold on the root masterpage or nested content controls. Interestingly, on the Controls collection, it shows the correct number of the page, however some are shown as null. I'm sure the nulls are where my controls I need to find are. Thanks DM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups