Nested PlaceHolders

Discussion in 'ASP .Net' started by DotNetGruven, Mar 2, 2004.

  1. DotNetGruven

    DotNetGruven Guest

    Hi,

    Is there a trick to using nested PlaceHolders?

    I have a WebForm that has 3 PlaceHolders on it:

    headerPlaceHolder
    contentPlaceHolder
    footerPlaceHolder

    Everything works well until I add a UserControl to the
    contentPlaceHolder which has 3 placeHolders on it:

    leftContentPlaceHolder
    centerContentPlaceHolder
    rightContentPlaceHolder

    All controls are added to place holders in the Page_Load event
    handler.

    I'm getting a null reference on the leftContentPlaceHolder.

    Any insight into this issue will be greatly appreciated!

    TIA,
    geo
     
    DotNetGruven, Mar 2, 2004
    #1
    1. Advertising

  2. DotNetGruven

    DotNetGruven Guest

    Additional information!

    The problem seems to be with UserControls that I'm using new instead of
    Page.LoadControl()!

    Some of the user controls that are being used have Properties that cause the
    content to be modified. So, I tried using new on them, then with the local
    reference, I'd set the properties and then use the local reference to add
    the control to the pages controls collection.

    So, the question now is:

    What is the difference between newing a UserControl and Loading a
    UserControl??

    TIA
    goe

    "DotNetGruven" <> wrote in message
    news:...
    > Hi,
    >
    > Is there a trick to using nested PlaceHolders?
    >
    > I have a WebForm that has 3 PlaceHolders on it:
    >
    > headerPlaceHolder
    > contentPlaceHolder
    > footerPlaceHolder
    >
    > Everything works well until I add a UserControl to the
    > contentPlaceHolder which has 3 placeHolders on it:
    >
    > leftContentPlaceHolder
    > centerContentPlaceHolder
    > rightContentPlaceHolder
    >
    > All controls are added to place holders in the Page_Load event
    > handler.
    >
    > I'm getting a null reference on the leftContentPlaceHolder.
    >
    > Any insight into this issue will be greatly appreciated!
    >
    > TIA,
    > geo
    >
    >
     
    DotNetGruven, Mar 2, 2004
    #2
    1. Advertising

  3. Hi Geo,

    Thanks for posting in the community!
    From your description, you have a custom ASP.NET UserControl(ascx) and you
    used it in a certain web page. You tried both using "new" constrcutor and
    the LoadControl( ascx file) to create a new control and found that the
    "new" constructor not worked. So you're wondering what''re the differences
    bewteen the two means,yes?

    As for this question, here are my suggestions on it:
    The ASP.NET UserControl is a kind of Template based controls which has its
    own template (in the ascx file), something like the include file in the
    classic asp. When using it in a certain container page. The ASP.NET runtime
    will first compile and generate the UserControl's class instance from the
    ascx source template. So generally, there're two means to add a ascx
    UserControl into a page:'
    1. Statically add it onto page via add UserControl's declaration and tag.

    2. Using LoadControl to dynamically load a UserControl instance from an
    ascx file.

    If you use "new" constructor to create a certain UserControl class
    instance, it doesn't load the control's source content from the ascx
    template, so it is not actually a complete UserControl instance. I think
    you should still use the LoadControl method and then set the certain
    properties of the controls before adding it to page.

    If you'd like to use "new" constructor to create a certain control instance
    like asp.net TextBox or Label, you need to develop a ASP.NET
    WebServerControl which is quite different from UserControl.

    Here are some tech reference on ASP.NET UserControl and WebSErver Control
    in MSDN:

    #Web Forms User Controls
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwebformsusercontro
    ls.asp?frame=true

    #Composite Control vs. User Control
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
    l/cpconcompositecontrolvsusercontrol.asp

    #ASP.NET Server Control Development Basics
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwebformscontroldev
    elopmentbasics.asp?frame=true

    Hope these help.



    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Mar 3, 2004
    #3
  4. Hi Geo,

    Have you had a chance to check out my suggestions or have you got any
    further ideas on this issue? If you have any thing unclear, please feel
    free to post here.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Mar 5, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bill Belliveau
    Replies:
    0
    Views:
    373
    Bill Belliveau
    Aug 19, 2003
  2. Colin Basterfield

    PlaceHolders

    Colin Basterfield, Dec 23, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    619
    Colin Basterfield
    Dec 24, 2003
  3. buran
    Replies:
    1
    Views:
    415
    Bruno Sirianni
    Apr 6, 2004
  4. Josh
    Replies:
    1
    Views:
    9,558
    Jeffrey Palermo [MCP]
    May 26, 2004
  5. Sinisa Ruzin
    Replies:
    0
    Views:
    865
    Sinisa Ruzin
    Oct 7, 2004
Loading...

Share This Page