Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Changing a control on a masterpage that uses a second masterpage

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Torben Laursen - 14 Mar 2008 14:11 GMT
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.FindControl("B1");
       System.Web.UI.WebControls.Button B20 =
(System.Web.UI.WebControls.Button)Master.FindControl("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
clintonG - 14 Mar 2008 14:38 GMT
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; }
//}

>I want to change the label of a component that I have on a masterpage but I
>cannot get my hands on it
[quoted text clipped - 12 lines]
>
> Thanks Torben
Torben Laursen - 14 Mar 2008 15:31 GMT
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

>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
[quoted text clipped - 33 lines]
>>
>> Thanks Torben
PJ on Development - 14 Mar 2008 20:51 GMT
Hi,

Let me see if I understood your problem

You have a scenario like this:

+------------
| Master Page 1
|
[quoted text clipped - 3 lines]
| | +----------
| | | 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").FindControl("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/NestedMasterPage.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

> Thanks,
>
[quoted text clipped - 46 lines]
>
> - Show quoted text -
clintonG - 15 Mar 2008 04:27 GMT
Which is why enabling trace is so useful for referencing controls.

<%= Clinton Gallagher

Hi,

Let me see if I understood your problem

You have a scenario like this:

+------------
| Master Page 1
|
[quoted text clipped - 3 lines]
| | +----------
| | | 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").FindControl("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/NestedMasterPage.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.work> wrote:
> Thanks,
>
[quoted text clipped - 52 lines]
>
> - Show quoted text -

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.