Add control to content aspx page of master page

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
 
M

Michael Nemtsev

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
 
R

Roger Frei

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?
 
M

Michael Nemtsev

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top