Avoiding a NullReferenceException on MasterPage

I went in to add a page to a site that's been alive for about 11 months. I wanted to add a page in a subfolder to test out some user/role setup on the subfolder, and instead have been debugging a NullReferenceException.

When my MasterPage.master.cs Page_Load ran, I found the root of the problem was all my controls appeared to be null, which was confusing since 'this' was live.

Bottom-line:

When I added my new page, I took the default given to me by Visual Studio after selecting my MasterPage.master. This page has an assortment of contentplaceholders on it, all but one of which is now handled by my MasterPage code. Since the page was irrelevant to the role-testing I was doing, I just accepted the default and tried running.

The fact is, I should have removed all the contentplaceholders that the MasterPage code was handling, because when it tried to execute the code-behind, it was trying to execute it on the content in the placeholders on my new page which were empty, so of course the controls were going to be null.

Removing the contentplaceholders on the new page allowed the MasterPage to do it's thing, and now my page is fine.

Happy Thanksgiving


No other words required:

http://www.sgtstrader.org/msg/2006tdm1.html



«November»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789