Expose a placeholder control in usercontrol

Discussion in 'ASP.NET / ASP.NET Core' started by nature, Jan 11, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I put a placeholder in an ascx file. I want to expose that placeholder and put a control on it.

    Ultimately, what I'm attempting to do is create a generic page layout in an ascx file and then plug in the controls as needed. E.g. I have an ascx file (call it template.ascx) containing a table where the first row is a header, the 2nd row is the body, the third row is a footer. I want to have a place holder control in the body and load in another ascx there.

    Perhaps there's a better way to do this. I'd appreciate any advice you can give. Thanks, Carl
     
  2. There probably will be a better way to do this, but I use this system all the time ...


    To add controls (e.g. "MyControl.ascx") to your placeholder (e.g. "phBody"), you can do this:
     
  3. thanks for the help but it doesn't quite work. I've tinkered with it to see if I can get it to work but I'm stuck. Any other suggestions?

    template.ascx contains:
    public sub LoadMyControl( c as System.Web.UI.Control) as System.Web.UI.Control

    plhColOne.Controls.Add(c)
    end sub

    Here's what happens:

    Compiler Error Message: BC30456: 'LoadMyControl' is not a member of 'System.Web.UI.Control'.</font id="red">
    Source Error:

    Line 18:
    Line 19: 'use the new method of mytemplate.ascx to load the second control
    Line 20: ctlTemplate.LoadMyControl(ctlOther)
    Line 21:
    Line 22: 'finally, load the mytemplate control on your starting page

    Source File: c:\inetpub\wwwroot\newfile.aspx Line: 20




    quote:Originally posted by steurm

    quote:Actually, if I'm adding a control to a placeholder on my page, this works fine. However, the placeholder is on another control.

    E.g. I'm in mypage.aspx that has mytemplate.ascx on it.
    I want to add a control to a placeholder on mytemplate.ascx from mypage.aspx.
    </blockquote id="quote"></font id="quote">
    You can make this work, through codebehind:

    First define a method on the mytemplate.ascx, which does the loading of other controls: (MyPH is the name of a PlaceHolder on mytemplate.ascx)
     
  4. Actually, if I'm adding a control to a placeholder on my page, this works fine. However, the placeholder is on another control.

    E.g. I'm in mypage.aspx that has mytemplate.ascx on it.
    I want to add a control to a placeholder on mytemplate.ascx from mypage.aspx.

    quote:Originally posted by steurm

    There probably will be a better way to do this, but I use this system all the time ...


    To add controls (e.g. "MyControl.ascx") to your placeholder (e.g. "phBody"), you can do this:
     
  5. quote:Actually, if I'm adding a control to a placeholder on my page, this works fine. However, the placeholder is on another control.

    E.g. I'm in mypage.aspx that has mytemplate.ascx on it.
    I want to add a control to a placeholder on mytemplate.ascx from mypage.aspx.
    </blockquote id="quote"></font id="quote">
    You can make this work, through codebehind:

    First define a method on the mytemplate.ascx, which does the loading of other controls: (MyPH is the name of a PlaceHolder on mytemplate.ascx)
     
  6. You gave a really good explanation that makes sense to me but it still gives the same error. I really, really appreciate the help though. Unless someone knows what this error is, I'm going to let it rest for now.

    Compiler Error Message: BC30456: 'LoadMyControl' is not a member of 'System.Web.UI.Control'.
    Source Error:


    quote:Originally posted by steurm

    quote:thanks for the help but it doesn't quite work. I've tinkered with it to see if I can get it to work but I'm stuck. Any other suggestions?

    </blockquote id="quote"></font id="quote">

    I'm not familiar with VB.NET, but I tried it out and here is the code that works for me:

    <ul>[*]I have 1 webform (StartPage.aspx) and 2 usercontrols (mytemplate.ascx and OtherControl.ascx)
    [*] Othercontrol only has some html-content to show [*]mytemplate.ascx has the following method (MyPH is a placeholder control on mytemplate.ascx:
     
  7. quote:thanks for the help but it doesn't quite work. I've tinkered with it to see if I can get it to work but I'm stuck. Any other suggestions?

    </blockquote id="quote"></font id="quote">

    I'm not familiar with VB.NET, but I tried it out and here is the code that works for me:

    <ul>[*]I have 1 webform (StartPage.aspx) and 2 usercontrols (mytemplate.ascx and OtherControl.ascx)
    [*] Othercontrol only has some html-content to show [*]mytemplate.ascx has the following method (MyPH is a placeholder control on mytemplate.ascx:
     
  8. Bruce

    Bruce DiscountASP.NET Staff

    LoadMyControl is a subroutine. You have to include that in your code.

    quote:Originally posted by nature

    You gave a really good explanation that makes sense to me but it still gives the same error. I really, really appreciate the help though. Unless someone knows what this error is, I'm going to let it rest for now.

    Compiler Error Message: BC30456: 'LoadMyControl' is not a member of 'System.Web.UI.Control'.
    Source Error:


    quote:Originally posted by steurm

    quote:thanks for the help but it doesn't quite work. I've tinkered with it to see if I can get it to work but I'm stuck. Any other suggestions?

    </blockquote id="quote"></font id="quote">

    I'm not familiar with VB.NET, but I tried it out and here is the code that works for me:

    <ul>[*]I have 1 webform (StartPage.aspx) and 2 usercontrols (mytemplate.ascx and OtherControl.ascx)
    [*] Othercontrol only has some html-content to show [*]mytemplate.ascx has the following method (MyPH is a placeholder control on mytemplate.ascx:
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page