473,581 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing a control on a masterpage that uses a second masterpage

I want to change the label of a component that I have on a masterpage but I
cannot get my hands on it
I have a mastepage MP2 that has a button called B2
masterpage MP2 uses masterpage MP1 that has a button called B1

I then have a page called default and in the page load I tryed:
System.Web.UI.W ebControls.Butt on B10 =
(System.Web.UI. WebControls.But ton)Master.Find Control("B1");
System.Web.UI.W ebControls.Butt on B20 =
(System.Web.UI. WebControls.But ton)Master.Find Control("B2");

However both B10 and B20 is null.

So how do I get my hands on B1 and B2 so I can set there label?

Thanks Torben

Mar 14 '08 #1
4 1823
I haven't used --nested-- Master Pages yet but they must still compile into
the same control tree as any other page. I've had insight by enabling
trace="true" on the page and then looking for the control I wanted to
reference in the control tree. Then its a matter of using the FindControl
method which gets ugly as it often has to be used repeatedly in the same
statement. That is what is called late binding.

You can try early binding by developing a Property for the label control
which allows direct access to the control by referencing its property.
Here's some notes I copied out of a file...

//A master page can expose properties by simply making
//those properties public within the master page.

//private string _someProperty;
//public string SomeProperty
//{
// get { return _someProperty; }
// set { _someProperty = value; }
//}
"Torben Laursen" <do**@not.workw rote in message
news:5B******** *************** ***********@mic rosoft.com...
>I want to change the label of a component that I have on a masterpage but I
cannot get my hands on it
I have a mastepage MP2 that has a button called B2
masterpage MP2 uses masterpage MP1 that has a button called B1

I then have a page called default and in the page load I tryed:
System.Web.UI.W ebControls.Butt on B10 =
(System.Web.UI. WebControls.But ton)Master.Find Control("B1");
System.Web.UI.W ebControls.Butt on B20 =
(System.Web.UI. WebControls.But ton)Master.Find Control("B2");

However both B10 and B20 is null.

So how do I get my hands on B1 and B2 so I can set there label?

Thanks Torben
Mar 14 '08 #2
Thanks,

I tryed this. I made a property on both master pages so I can access the 2
buttons.

But using this method I can only get MP2.

So I still need a way to access both B1 and B2

Torben

"clintonG" <no****@nowhere .comwrote in message
news:ey******** ******@TK2MSFTN GP04.phx.gbl...
>I haven't used --nested-- Master Pages yet but they must still compile into
the same control tree as any other page. I've had insight by enabling
trace="true" on the page and then looking for the control I wanted to
reference in the control tree. Then its a matter of using the FindControl
method which gets ugly as it often has to be used repeatedly in the same
statement. That is what is called late binding.

You can try early binding by developing a Property for the label control
which allows direct access to the control by referencing its property.
Here's some notes I copied out of a file...

//A master page can expose properties by simply making
//those properties public within the master page.

//private string _someProperty;
//public string SomeProperty
//{
// get { return _someProperty; }
// set { _someProperty = value; }
//}
"Torben Laursen" <do**@not.workw rote in message
news:5B******** *************** ***********@mic rosoft.com...
>>I want to change the label of a component that I have on a masterpage but
I cannot get my hands on it
I have a mastepage MP2 that has a button called B2
masterpage MP2 uses masterpage MP1 that has a button called B1

I then have a page called default and in the page load I tryed:
System.Web.UI.W ebControls.Butt on B10 =
(System.Web.UI .WebControls.Bu tton)Master.Fin dControl("B1");
System.Web.UI.W ebControls.Butt on B20 =
(System.Web.UI .WebControls.Bu tton)Master.Fin dControl("B2");

However both B10 and B20 is null.

So how do I get my hands on B1 and B2 so I can set there label?

Thanks Torben
Mar 14 '08 #3
Hi,

Let me see if I understood your problem

You have a scenario like this:

+------------
| Master Page 1
|
| +-----------
| | Master Page 2
| |
| | +----------
| | | Content Page
| | |

And you're trying to access from Content Page a control on the Master
Page 1. Am I correct?

If so, I think you can do the following

Private Sub ContentPage_Loa d(sender as Object, e as EventArgs) Handles
Me.Load

Dim mp2 As MasterPage = Me.Master
Dim mp1 As MasterPage = mp2.Master

Dim btn1 As Button = CType(mp1.FindC ontrol("btnMast er1"),
Button)
Dim btn2 As Button =
CType(mp1.FindC ontrol("Content PlaceHolder1"). FindControl("bt nMaster2"),
Button)

btn1.Text = "MP1 Changed from Content Page"
btn2.Text = "MP2 Changed from Content Page"

End Sub

I've put up a sample test project at http://rapidshare.com/files/99551862...rPage.zip.html

Anyways, the problem is that when using nested Master Pages, the
hierarchy is created on the top most Master Page.

And as you can see by the code snippet the ContentPlaceHol der is build
into the hierarchy.

Regards,

Paulo Santos
http://pjondevelopment.50webs.com
On Mar 14, 11:31*am, "Torben Laursen" <d...@not.workw rote:
Thanks,

I tryed this. I made a property on both master pages so I can access the 2
buttons.

But using this method I can only get MP2.

So I still need a way to access both B1 and B2

Torben

"clintonG" <nob...@nowhere .comwrote in message

news:ey******** ******@TK2MSFTN GP04.phx.gbl...
I haven't used --nested-- Master Pages yet but they must still compile into
the same control tree as any other page. I've had insight by enabling
trace="true" on the page and then looking for the control I wanted to
reference in the control tree. Then its a matter of using the FindControl
method which gets ugly as it often has to be used repeatedly in the same
statement. That is what is called late binding.
You can try early binding by developing a Property for the label control
which allows direct access to the control by referencing its property.
Here's some notes I copied out of a file...
//A master page can expose properties by simply making
//those properties public within the master page.
//private string _someProperty;
//public string SomeProperty
//{
// * *get { return _someProperty; }
// * *set { _someProperty = value; }
//}
"Torben Laursen" <d...@not.workw rote in message
news:5B******** *************** ***********@mic rosoft.com...
>I want to change the label of a component that I have on a masterpage but
I cannot get my hands on it
I have a mastepage MP2 that has a button called B2
masterpage MP2 uses masterpage MP1 that has a button called B1
I then have a page called default and in the page load I tryed:
* * * *System.Web.UI. WebControls.But ton B10 =
(System.Web.UI. WebControls.But ton)Master.Find Control("B1");
* * * *System.Web.UI. WebControls.But ton B20 =
(System.Web.UI. WebControls.But ton)Master.Find Control("B2");
However both B10 and B20 is null.
So how do I get my hands on B1 and B2 so I can set there label?
Thanks Torben- Hide quoted text -

- Show quoted text -
Mar 14 '08 #4
Which is why enabling trace is so useful for referencing controls.

<%= Clinton Gallagher
"PJ on Development" <pj************ *@gmail.comwrot e in message
news:dd******** *************** ***********@q78 g2000hsh.google groups.com...
Hi,

Let me see if I understood your problem

You have a scenario like this:

+------------
| Master Page 1
|
| +-----------
| | Master Page 2
| |
| | +----------
| | | Content Page
| | |

And you're trying to access from Content Page a control on the Master
Page 1. Am I correct?

If so, I think you can do the following

Private Sub ContentPage_Loa d(sender as Object, e as EventArgs) Handles
Me.Load

Dim mp2 As MasterPage = Me.Master
Dim mp1 As MasterPage = mp2.Master

Dim btn1 As Button = CType(mp1.FindC ontrol("btnMast er1"),
Button)
Dim btn2 As Button =
CType(mp1.FindC ontrol("Content PlaceHolder1"). FindControl("bt nMaster2"),
Button)

btn1.Text = "MP1 Changed from Content Page"
btn2.Text = "MP2 Changed from Content Page"

End Sub

I've put up a sample test project at
http://rapidshare.com/files/99551862...rPage.zip.html

Anyways, the problem is that when using nested Master Pages, the
hierarchy is created on the top most Master Page.

And as you can see by the code snippet the ContentPlaceHol der is build
into the hierarchy.

Regards,

Paulo Santos
http://pjondevelopment.50webs.com
On Mar 14, 11:31 am, "Torben Laursen" <d...@not.workw rote:
Thanks,

I tryed this. I made a property on both master pages so I can access the 2
buttons.

But using this method I can only get MP2.

So I still need a way to access both B1 and B2

Torben

"clintonG" <nob...@nowhere .comwrote in message

news:ey******** ******@TK2MSFTN GP04.phx.gbl...
I haven't used --nested-- Master Pages yet but they must still compile
into
the same control tree as any other page. I've had insight by enabling
trace="true" on the page and then looking for the control I wanted to
reference in the control tree. Then its a matter of using the FindControl
method which gets ugly as it often has to be used repeatedly in the same
statement. That is what is called late binding.
You can try early binding by developing a Property for the label control
which allows direct access to the control by referencing its property.
Here's some notes I copied out of a file...
//A master page can expose properties by simply making
//those properties public within the master page.
//private string _someProperty;
//public string SomeProperty
//{
// get { return _someProperty; }
// set { _someProperty = value; }
//}
"Torben Laursen" <d...@not.workw rote in message
news:5B******** *************** ***********@mic rosoft.com...
>I want to change the label of a component that I have on a masterpage
but
I cannot get my hands on it
I have a mastepage MP2 that has a button called B2
masterpage MP2 uses masterpage MP1 that has a button called B1
I then have a page called default and in the page load I tryed:
System.Web.UI.W ebControls.Butt on B10 =
(System.Web.UI. WebControls.But ton)Master.Find Control("B1");
System.Web.UI.W ebControls.Butt on B20 =
(System.Web.UI. WebControls.But ton)Master.Find Control("B2");
However both B10 and B20 is null.
So how do I get my hands on B1 and B2 so I can set there label?
Thanks Torben- Hide quoted text -

- Show quoted text -
Mar 18 '08 #5

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

Similar topics

0
1175
by: Mark Parter | last post by:
I've "converted" the code at http://www.eggheadcafe.com/articles/20040613.asp to VB.NET as I'd like to implement this as my application uses quite complex GridViews and various other controls on some pages (viewstate alone was 110Kb+ on some pages!!). Anyway, I've setup the classes required and created a test page which inherits from the...
5
1853
by: Rob Roberts | last post by:
Is there any way to change VS2005 to generate HTML 4.01/Strict instead of XHTML 1.0/Transititional? VS2005 puts a DOCTYPE statement specifying XHTML 1.0/Transitional at the top of every new aspx page. Is there any way to change it to specify an HTML 4.01/Strict DOCTYPE instead? Thanks in advance, --Rob Roberts
1
1865
by: rh | last post by:
Hi, My MasterPage contains a user control used for navigation. I have some .aspx pages that use this MasterPage and I would like to cache only the user control used for navigation. How do I go about doing so? I know that I can cache specific controls on a page by setting the VaryByControl property of the OutputCache directive. But if...
2
7671
by: dawg1998 | last post by:
I have a page that creates dynamic textboxes based on the number of fields a user chooses to fill out. This process worked great when the page was standalone. However, when I move to a Content/MasterPage setup, the MasterPage Form seems to be interfering with the ability of my code to retrieve the value in the dynamic control. Are there...
1
1340
by: Netmonster | last post by:
Hello, Can someone please explain the load order of different .net document types? Situation, I have a masterpage that has a few usercontrols on it, and an aspx page that uses the masterpage. I have noticed that the contenPlaceHolder on the aspx page runs before the masterpages PAGE_LOAD and any controls on the masterpage. Is this...
13
6212
by: Michael | last post by:
I have setup a public variable in the Master Page "code-behind-file". Now I would like to set that value from the UserControl, but I can't seem to find a way to do this. Does anyone have any ideas? I'm basically trying to set it up so that I can keep the User infor (userid, ect) in the Masterpage so that other pages can access it. Thanks for...
6
2215
by: Lucas Ponzo | last post by:
I nedd depending on thr user loged in, that the menu binds to a different site.map file ... can I have multiple site maps in my ASP.NET 2.0 app and change the file that the SiteMapDataSource is bound to ? I no, what was a better solution for that with no use of roles features ? Thanks. -- Lucas Ponzo
1
1798
by: =?Utf-8?B?bWFya203NQ==?= | last post by:
There is probably some simple answer to my question, but i'm still new to this a bit.. I have a master page.. with a menu system which is coded onto the masterpage.aspx... it uses A tags with hrefs etc.. the usual stuff.. I also have a sub section on the site.. where aspx files arent in the root.. ie: /rootfiles.aspx here.. then...
5
2706
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm trying to make my code as streamlined as possible, and add CSS file references dynamically when they are required, for example, if a page contains a webcontrol, then the related CSS file is added by the webcontrol. This prevents me having to remember to add the CSS file to the page if I use a certain webcontrol. I have a...
0
7876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7804
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6563
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.