Delete an <asp:content> control in PreInit?

Last post 08-23-2007 12:10 PM by noobjk. 4 replies.

Sort Posts:

  • Delete an <asp:content> control in PreInit?

    08-21-2007, 6:30 PM
    • Participant
      1,342 point Participant
    • noobjk
    • Member since 06-16-2003, 7:21 AM
    • Posts 294

    I have a page with two <asp:content> controls:

    <asp:content ContentPlaceholderId="foo" id="content1">some content</asp:content>
    <asp:content ContentPlaceholderId="bar" id="content2">some other content</asp:content>

    In PreInit, I can set Page.MasterPageFile to whichever masterpage I want. But, if the masterpage I use doesn't have a contentPlaceholder called "bar", ASP.NET will throw an exception. So I want to find & delete that second <asp:content> control in PreInit -- before the MasterPage gets merged.

    So far, I haven't found any way of accessing the <asp:content> controls... anybody out there know how?

  • Re: Delete an <asp:content> control in PreInit?

    08-22-2007, 1:14 AM
    • Member
      104 point Member
    • jc740
    • Member since 08-22-2007, 1:56 AM
    • New York
    • Posts 17

    According to the documentation:

     http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.content(VS.80).aspx 

     
    "...A Content control is not added to the control hierarchy at runtime."

     

    Can you provide a bit more detail as to what you are trying to accomplish?  I think I may be able to assist you with an alternative method.

     

    John 

  • Re: Delete an <asp:content> control in PreInit?

    08-22-2007, 9:15 AM
    Answer
    • Participant
      1,342 point Participant
    • noobjk
    • Member since 06-16-2003, 7:21 AM
    • Posts 294

    Hmm, that's definitely going to make it harder for me to find using FindControl!

    The problem I'm trying to solve is this: I've got a bunch of pages that are sometimes accessed by logged-in users, and sometimes by not-logged-in users. I wanted to simply switch the masterpage file in the PreInit handler to show the appropriate masterpage in each case. But one masterpage has TWO contentplaceholders, and the other has only one. Yes, I could add a bogus placeholder to the other masterpage, but I thought I'd see if there were some cleaner way of saying, "for these pages, don't try to merge the second content control if we're using the masterpage with only one placeholder."

  • Re: Delete an <asp:content> control in PreInit?

    08-22-2007, 10:52 PM
    • Member
      104 point Member
    • jc740
    • Member since 08-22-2007, 1:56 AM
    • New York
    • Posts 17

    I've have a content mgmt system that i've put together where I have a MasterPage (contains all common site features, ie Header, Footer) with a single content placeholder.  My ContentPage has a single content control AND a placeholder as well.  Then I have "templates" which are basically ASCX files which have any number of placeholders themselves.  At runtime, on the content page, I load the appropriate template using loadcontrol, populate the placeholders, and add that template ascx to the content page placeholder.  This is all DB driven and works extremely well.  It also incorporates url rewrtting, so theres no messy urls either.

    If it sounds like there's something there to help you out, let me know and I'd be happy to share some of the code with you...

     John 


     

  • Re: Delete an <asp:content> control in PreInit?

    08-23-2007, 12:10 PM
    • Participant
      1,342 point Participant
    • noobjk
    • Member since 06-16-2003, 7:21 AM
    • Posts 294

    Thanks, John. In this case, the number of pages is small enough that we don't need a full CMS. I think we'll probably just fork the pages and move on.

Page 1 of 1 (5 items)