Solved

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

Posted on 2011-09-23
3
484 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Initial get page response times and IIS8 15 51
jquery datatables, asp.net MVC 9 42
Sort GridView by ID Descending 1 13
RegEx with optional part 4 26
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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