Solved

Access a H1 tag inside the parent master page thru a content page

Posted on 2011-09-23
3
457 Views
Last Modified: 2012-05-12
I have a H1 tag in the body of my Parent Master Page. My content page is based on nested master page. I am trying to access the H1 tag in this content page using the code behind.

My site it built in asp.net 2.0 and C#.

In the Page_Load of my content page I am trying to access it like this>

HtmlGenericControl h1 = (HtmlGenericControl)Master.Master.FindControl("h1top");
                    h1.InnerText = "this is a test";

Open in new window


Didn't work throws an error


System.NullReferenceException: Object reference not set to an instance of an object.
   at mysite.product.Page_Load(Object sender, EventArgs e) in http://server/TestsiteLatest/browse/product.aspx.cs:line 102

line 102 is h1.InnerText = "this is a test";

where am i making an error in writing the code.

Thanks and appreciate it
0
Comment
Question by:niceoneishere
3 Comments
 
LVL 15

Accepted Solution

by:
Eyal earned 250 total points
ID: 36594336
see this page for detailed instructions of how to do this

http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 250 total points
ID: 36599409
In order to use FindControl, the element needs the runat="server" attribute.  I wouldn't think that the <h1> element would have that.
0
 
LVL 1

Author Closing Comment

by:niceoneishere
ID: 37017923
thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

705 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now