473,473 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Create 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.WebControls.Button B10 =
(System.Web.UI.WebControls.Button)Master.FindContr ol("B1");
System.Web.UI.WebControls.Button B20 =
(System.Web.UI.WebControls.Button)Master.FindContr ol("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 1812
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.workwrote in message
news:5B**********************************@microsof t.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.Button B10 =
(System.Web.UI.WebControls.Button)Master.FindContr ol("B1");
System.Web.UI.WebControls.Button B20 =
(System.Web.UI.WebControls.Button)Master.FindContr ol("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**************@TK2MSFTNGP04.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.workwrote in message
news:5B**********************************@microsof t.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.Button B10 =
(System.Web.UI.WebControls.Button)Master.FindCont rol("B1");
System.Web.UI.WebControls.Button B20 =
(System.Web.UI.WebControls.Button)Master.FindCont rol("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_Load(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.FindControl("btnMaster1"),
Button)
Dim btn2 As Button =
CType(mp1.FindControl("ContentPlaceHolder1").FindC ontrol("btnMaster2"),
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 ContentPlaceHolder is build
into the hierarchy.

Regards,

Paulo Santos
http://pjondevelopment.50webs.com
On Mar 14, 11:31*am, "Torben Laursen" <d...@not.workwrote:
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**************@TK2MSFTNGP04.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.workwrote in message
news:5B**********************************@microsof t.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.Button B10 =
(System.Web.UI.WebControls.Button)Master.FindContr ol("B1");
* * * *System.Web.UI.WebControls.Button B20 =
(System.Web.UI.WebControls.Button)Master.FindContr ol("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.comwrote in message
news:dd**********************************@q78g2000 hsh.googlegroups.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_Load(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.FindControl("btnMaster1"),
Button)
Dim btn2 As Button =
CType(mp1.FindControl("ContentPlaceHolder1").FindC ontrol("btnMaster2"),
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 ContentPlaceHolder is build
into the hierarchy.

Regards,

Paulo Santos
http://pjondevelopment.50webs.com
On Mar 14, 11:31 am, "Torben Laursen" <d...@not.workwrote:
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**************@TK2MSFTNGP04.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.workwrote in message
news:5B**********************************@microsof t.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.Button B10 =
(System.Web.UI.WebControls.Button)Master.FindContr ol("B1");
System.Web.UI.WebControls.Button B20 =
(System.Web.UI.WebControls.Button)Master.FindContr ol("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
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...
5
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...
1
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...
2
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...
1
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. ...
13
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?...
6
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...
1
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...
5
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...
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
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,...
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...
1
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.