Add control to content aspx page of master page

Discussion in 'ASP .Net' started by Roger Frei, Apr 27, 2007.

  1. Roger Frei

    Roger Frei Guest

    hello everybody

    I have a masterpage and several aspx pages that inerhit controls from the
    masterpage. In the Page_Load event of the content aspx page I want to add
    some controls. Example code:

    protected void Page_Load(object sender, EventArgs e) {
    if (!Page.IsPostBack) {
    Table table = new Table();
    Page.Controls.Add(table);
    }
    }

    But this code adds the control at the end of the masterpage and not add the
    end of the content page! How can I add a control at the and of the content
    aspx page assuming that it extends a masterpage?
    I also tried it with the FindControl(..) method but this is very hard as my
    page structure is nested. Additionally, such code wouldn't be very
    maintainable --> Control cx = this.FindControl("contentPlaceHolder");

    Thank you in advance for your help!

    Regards,
    Roger
     
    Roger Frei, Apr 27, 2007
    #1
    1. Advertising

  2. Hello Roger,

    RF> But this code adds the control at the end of the masterpage and not add
    the
    RF>end of the content page!
    RF> nested. Additionally, such code wouldn't be very maintainable -->
    RF> Control cx = this.FindControl("contentPlaceHolder");

    What's wrong with this approaches? It's very readable and clear that you
    add your control exatly at contentPlaceHolder.

    ---
    WBR, Michael Nemtsev [.NET/C# MVP].
    My blog: http://spaces.live.com/laflour
    Team blog: http://devkids.blogspot.com/

    "The greatest danger for most of us is not that our aim is too high and we
    miss it, but that it is too low and we reach it" (c) Michelangelo
     
    Michael Nemtsev, Apr 27, 2007
    #2
    1. Advertising

  3. Roger Frei

    Roger Frei Guest

    yes, but the contentPlaceHolder may be nested somewhere in the page. I would
    have to write..:

    this.FindControl("xxx").FindControl("yyy").FindControl("myPlaceHolder")

    or is there another (easier) way to get a control?



    "Michael Nemtsev" <> schrieb im Newsbeitrag
    news:...
    > Hello Roger,
    >
    > RF> But this code adds the control at the end of the masterpage and not
    > add the RF>end of the content page!
    > RF> nested. Additionally, such code wouldn't be very maintainable -->
    > RF> Control cx = this.FindControl("contentPlaceHolder");
    >
    > What's wrong with this approaches? It's very readable and clear that you
    > add your control exatly at contentPlaceHolder.
    >
    > ---
    > WBR, Michael Nemtsev [.NET/C# MVP]. My blog:
    > http://spaces.live.com/laflour
    > Team blog: http://devkids.blogspot.com/
    >
    > "The greatest danger for most of us is not that our aim is too high and we
    > miss it, but that it is too low and we reach it" (c) Michelangelo
    >
    >
     
    Roger Frei, Apr 27, 2007
    #3
  4. Hello Roger,

    Write you onw wrapper which will find the desired contol


    ---
    WBR, Michael Nemtsev [.NET/C# MVP].
    My blog: http://spaces.live.com/laflour
    Team blog: http://devkids.blogspot.com/

    "The greatest danger for most of us is not that our aim is too high and we
    miss it, but that it is too low and we reach it" (c) Michelangelo

    RF> yes, but the contentPlaceHolder may be nested somewhere in the page.
    RF> I would have to write..:
    RF>
    RF> this.FindControl("xxx").FindControl("yyy").FindControl("myPlaceHolde
    RF> r")
    RF>
    RF> or is there another (easier) way to get a control?
    RF>
    RF> "Michael Nemtsev" <> schrieb im Newsbeitrag
    RF> news:...
    RF>
    >> Hello Roger,
    >>
    >> RF> But this code adds the control at the end of the masterpage and
    >> not
    >> add the RF>end of the content page!
    >> RF> nested. Additionally, such code wouldn't be very maintainable -->
    >> RF> Control cx = this.FindControl("contentPlaceHolder");
    >> What's wrong with this approaches? It's very readable and clear that
    >> you add your control exatly at contentPlaceHolder.
    >>
    >> ---
    >> WBR, Michael Nemtsev [.NET/C# MVP]. My blog:
    >> http://spaces.live.com/laflour
    >> Team blog: http://devkids.blogspot.com/
    >> "The greatest danger for most of us is not that our aim is too high
    >> and we miss it, but that it is too low and we reach it" (c)
    >> Michelangelo
    >>
     
    Michael Nemtsev, Apr 27, 2007
    #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. Doug McCann
    Replies:
    1
    Views:
    1,045
    William Brogden
    Aug 5, 2004
  2. Replies:
    0
    Views:
    726
  3. Rolf Welskes
    Replies:
    7
    Views:
    969
    Steven Cheng[MSFT]
    Aug 22, 2006
  4. Replies:
    1
    Views:
    1,288
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,499
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page