Add control to content aspx page of master page

  • Thread starter Thread starter Roger Frei
  • Start date Start date
R

Roger Frei

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
 
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
 
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?
 
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> 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
 
Back
Top