?
Solved

Access control in nested master page template

Posted on 2006-06-05
2
Medium Priority
?
904 Views
Last Modified: 2012-08-14
I'm trying to access different controls that are located in both of my nested master page templates. Here is a little diagram to keep us all on the same page...

HeaderMaster.master <-- SubPageMaster.master <-- AboutUs.aspx

HeaderMaster.master contains <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> and SubPageMaster.master contains <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>.

My goal is to change the text of each Label from the AboutUs.aspx pageload sub routine.

This code CType(Master.FindControl("Label1"), Label).Text = "blah" seems to work fine when using just one template, but when using it in a nested setup I get this error: System.NullReferenceException: Object reference not set to an instance of an object.

Would someone please tell me how I can access the controls in each template?

Thanks!
0
Comment
Question by:graphicodyssey
2 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 2000 total points
ID: 16840678
oh well, one master page is bad enough.

try using trace="true" in the header and then check the full html name of the control you want eg $ctrl01$label1 and then use this in the findcontrol
0
 
LVL 1

Author Comment

by:graphicodyssey
ID: 16847156
I didn't use the full control name, but your comment of the Trace made me review the control structure a little more. What I found out was... even though the control is in the SubPageMaster file, it really lives in the Content Place Holder used in it's parent. So to get to a control on the SubPage, you need to go to the very top and work your way down, which would be... Master.Master.BodyContent.Label2 (where BodyContent is the ID of the ContentPlaceHolder control in the HeaderMaster file). To access a control within the HeaderMaster, you would simply use Master.Master.Label1. If you wanted to access a control within a ContentPlaceHolder control on the AboutUs page, you would need something like Master.Master.BodyContent.SubContent.Label3.

In any case, thanks for your assistance... it pointed me in the right direction.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question