Master Pages and Usercontrols - object reference not set

J

j-in-uk

I have 3 pages Site.master, Album.aspx and ContinentsMenu.ascx.
Continents is a usercontrol placed in Albums. In Album.aspx.cs I need
to access a property from the Continents usercontrol and is done using
the code below. When I add masterpages to Album.aspx and remove all the
html tags I get the error System.NullReferenceException: Object
reference not set to an instance of an object.in the line marked ******
below. I notice once I insert the following line back<!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> back to the Album.aspx
page and remove the masterpage references it works fine. Any ideas on
how i can access my usercontrol using masterpages?

private ContinentsMenu _continentList;

override protected void OnInit(System.EventArgs e)
{base.OnInit(e);
InitializeComponent();
_continentList = ((ContinentsMenu)(FindControl("ContinentsMenu1")));
}

protected void Page_Load(object sender, System.EventArgs e)
******{_albumPath = Path.Combine(_photosPath,
_continentList.SelectedContinent);}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top