Access container during OnInit

Discussion in 'ASP .Net Building Controls' started by Peter Zolja, Jan 30, 2007.

  1. Peter Zolja

    Peter Zolja Guest

    Here's my scenario:

    In my ASPX file I have something like this:

    <cc:MyContainer runat="server" ID="MyContainer1" FunkyClassName="Class1">

    <cc:MyControl runat="server" ID="MyControl1"
    FunkyObject-SomeProperty="text">

    </cc:MyContainer>

    What I'm trying to do is have the "FunkyObject" be created dynamically using
    reflection based on the container's "FunkyClassName" property value.
    Everything works until the ASPX file actually looks like above. In this case
    the framework tries to set MyControl1's FunkyObject-SomeProperty to "text"
    in the initialize phase (OnInit). The problem is that at this stage the
    control tree is not fully built and MyControl1 cannot access the parent
    container to find out what kind of type the FunkyObject should be. As far as
    I know this is by design, so it's behaving like it should.

    My question is: can you think of a way (hack?) around this? I could move the
    FunkyClassName="Class1" declaration inside MyControl or store that value in
    web.config, however, the best way (for my case) would be if I could store it
    as a property of the container...

    Any ideas?

    Thank you,
    Peter.
     
    Peter Zolja, Jan 30, 2007
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.