473,395 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Add control to content aspx page of master page

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


Apr 27 '07 #1
3 6528
Hello Roger,

RFBut this code adds the control at the end of the masterpage and not add
the
RF>end of the content page!
RFnested. Additionally, such code wouldn't be very maintainable -->
RFControl 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
Apr 27 '07 #2
yes, but the contentPlaceHolder may be nested somewhere in the page. I would
have to write..:

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

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

"Michael Nemtsev" <ne*****@msn.comschrieb im Newsbeitrag
news:a2***************************@msnews.microsof t.com...
Hello Roger,

RFBut this code adds the control at the end of the masterpage and not
add the RF>end of the content page!
RFnested. Additionally, such code wouldn't be very maintainable -->
RFControl 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


Apr 27 '07 #3
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

RFyes, but the contentPlaceHolder may be nested somewhere in the page.
RFI would have to write..:
RF>
RFthis.FindControl("xxx").FindControl("yyy").FindC ontrol("myPlaceHolde
RFr")
RF>
RFor is there another (easier) way to get a control?
RF>
RF"Michael Nemtsev" <ne*****@msn.comschrieb im Newsbeitrag
RFnews:a2***************************@msnews.micros oft.com...
RF>
>Hello Roger,

RFBut this code adds the control at the end of the masterpage and
not
add the RF>end of the content page!
RFnested. Additionally, such code wouldn't be very maintainable -->
RFControl 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

Apr 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David | last post by:
In ASP.NET 2.0, is it possible to use a control that's on a Master Page as a select parameter in a content page's datasource control? For example, the Master Page has a drop down list of...
2
by: Steve Franks | last post by:
I am trying to access strongly typed properties in a page's master page from the content page. I followed an article that describes how to do this, and it seems quite straight forward. However...
8
by: PJ | last post by:
How can I get a reference to the master page class? It is defined as a partial class, but I cannot seem to type a variable to the name of the partial class? The compiler continually shows "The...
2
by: damiensawyer | last post by:
Hello all, I'm wondering if someone can help me with an issue. I have a master page that has a treeview control on it (inside an ascx file). Also on the master page I have a content...
0
by: nemesis.saurabh | last post by:
hi, i am using VS 2005. i have created a master.master. i have added 2 content placeholders, i am able to edit them in the corresponding content page but if i am adding anymore placeholders in...
11
by: McKirahan | last post by:
I am looking for feedback on an approach to using PHP. Below is a stripped down version of a Home page: "index.php". The content of the site is displayed in the middle of the page and is...
1
by: Asif | last post by:
Hi All, I did follow the MSDN article (http://msdn2.microsoft.com/en-us/ library/ms379585(VS.80).aspx ) for overriding Master Page properties by setting page title and other Meta information(...
0
by: robgallen | last post by:
I have 2 user controls within a master page, and I would like one of them to call a function in the other. All the examples I have seen involve a page communicating with the Master page, or with...
3
by: John Kotuby | last post by:
Hi all, Just wondering why this would happen. I had created a standalone ASPX page in which 5 controls are wrapped in an UpdatePanel. The idea is Control1 selection populates Control2 then...
7
econVictim
by: econVictim | last post by:
I have a standard html form in a masterpage that is part of a search engine on a separate page... <form id="fsearch" action="search.aspx" method="post"> <table border="0" cellpadding="0"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.