473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

MasterPages & UserControls - object reference not set

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. for the highlighted
yellow line 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);}

Aug 14 '06 #1
3 4285
Hi,

Your .aspx markup is probably invalid but it's hard to say without seeing it. To see valid markup for an implementation of the
content of a master page (assuming your using VS.NET 2005), add a new web page to your project but before continuing check the
"choose a master page" checkbox. After you close the "New File" dialog another opens. Select Site.master from the list and
continue.

Look at the content of the new page to see valid markup.

--
Dave Sexton

"j-in-uk" <je******@gmail.comwrote in message news:11*********************@75g2000cwc.googlegrou ps.com...
>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. for the highlighted
yellow line 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);}

Aug 14 '06 #2
Hi Dave,

Yes that's what I did when I added my Album.aspx page I selected
Site.master option, for all my other pages it works fine. Just my
album.apx page which has a usercontrol, it throws a
System.NullReferenceException error on the following line for
_continent.SelectedContinent

protected void Page_Load(object sender, System.EventArgs e)
{_albumPath = Path.Combine(_photosPath,
_continentList.SelectedContinent);}
Dave Sexton wrote:
Hi,

Your .aspx markup is probably invalid but it's hard to say without seeing it. To see valid markup for an implementation of the
content of a master page (assuming your using VS.NET 2005), add a new web page to your project but before continuing check the
"choose a master page" checkbox. After you close the "New File" dialog another opens. Select Site.master from the list and
continue.

Look at the content of the new page to see valid markup.

--
Dave Sexton

"j-in-uk" <je******@gmail.comwrote in message news:11*********************@75g2000cwc.googlegrou ps.com...
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. for the highlighted
yellow line 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);}
Aug 14 '06 #3
Hi,

Try using the following in the OnInit event handler:

phMenu.Controls.Add(Page.LoadControl("~/ContinentsMenu.ascx"))

where phMenu is declared in the .aspx page where you want your UserControl to be loaded:

<asp:PlaceHolder runat="server" ID="phMenu" />

HTH

--
Dave Sexton

"j-in-uk" <je******@gmail.comwrote in message news:11*********************@b28g2000cwb.googlegro ups.com...
Hi Dave,

Yes that's what I did when I added my Album.aspx page I selected
Site.master option, for all my other pages it works fine. Just my
album.apx page which has a usercontrol, it throws a
System.NullReferenceException error on the following line for
_continent.SelectedContinent

protected void Page_Load(object sender, System.EventArgs e)
{_albumPath = Path.Combine(_photosPath,
_continentList.SelectedContinent);}
Dave Sexton wrote:
>Hi,

Your .aspx markup is probably invalid but it's hard to say without seeing it. To see valid markup for an implementation of the
content of a master page (assuming your using VS.NET 2005), add a new web page to your project but before continuing check the
"choose a master page" checkbox. After you close the "New File" dialog another opens. Select Site.master from the list and
continue.

Look at the content of the new page to see valid markup.

--
Dave Sexton

"j-in-uk" <je******@gmail.comwrote in message news:11*********************@75g2000cwc.googlegrou ps.com...
>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. for the highlighted
yellow line 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);}

Aug 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Emma | last post by:
Hi, I'm developing a GUI with almost all Usercontrols. It's been working wonderfull up till a few weeks ago, and really crashed yesterday. Suddenly I can no longer add some of my usercontrols...
4
by: Andy Breward | last post by:
Hi I have created a range of usercontrols for displaying various bits of information. My question is if I wish to pass a parameter to the UserControl from the host page, is this possible? I...
4
by: Anders K. Jacobsen [DK] | last post by:
Hi I have some common UserControls i want to share between to sites (on the same mashine but on diffrent virtual paths). right now i have on solution file with aprox 10 projects. 2 of these is...
2
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page...
0
by: David Rose | last post by:
I have an existing asp.net web application which contains several user controls. Some of these user controls contain other user controls (generic controls) which are located in a subdirectory. Now...
2
by: iturner100 | last post by:
Hi, I've been struggling with this one for a couple of hours without much joy. Basically, I've got a set of nested masterpages (3 as it happens). I'm dynamically generating a new page in code...
0
by: seigo | last post by:
Hello, I faced with the following problem. I have a PlaceHolder on a page and a few UserControls which have custom events, for instance: public delegate void SelectHandler(object sender,...
10
by: =?Utf-8?B?TWlrZSBNY0FsbGlzdGVy?= | last post by:
I have a partial class of a UserControl coded as follows: public partial class Login : System.Windows.Controls.UserControl { public delegate void StartingLoginHandler(string message); public...
7
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.