Dynamically loading user control into Placeholder gives Object reference not set to an instance of an object
- From: "Phoenix" <phoenixjenn@xxxxxxxxx>
- Date: 6 Jun 2005 05:13:44 -0700
I've created user controls that contain listboxes that are dynamically
populated from the database. In the html view of the user control
(ucSectorsIndustries.ascx) is the <asp:listbox id="lbSector"
runat="server" Rows="5"></asp:listbox> code. In the codebehind I have
the following:
Protected WithEvents lbSector As System.Web.UI.WebControls.ListBox
....
On Page_Load of the user control I have
For i As Integer = 0 To 5
lbIndustry.Items.Add(New ListItem("----", ""))
Next
lbIndustry.DataBind()
This usercontrol works great in a page on which it is dropped via the
GUI, but on another page where it is loaded like this:
Dim mySectorsIndustries As ucSectorsIndustries = New
ucSectorsIndustries
PlaceHolder1.Controls.Add(mySectorsIndustries)
it seems to be NULL and gives the old "
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object."
Source Error: (Line 69 is Red)
Line 68: For i As Integer = 0 To 5
Line 69: lbIndustry.Items.Add(New ListItem("----", ""))
Line 70: Next
Line 71: lbIndustry.DataBind()
I have a feeling it is the way it is instantiating the object, but I
don't know how to fix it...It is as if the HTML part of the user
control is loading AFTER the Page_Load in the codebehind. Please help.
.
- Follow-Ups:
- Prev by Date: Re: EditCommandColumn problem!!
- Next by Date: Re: Dynamically loading user control into Placeholder gives Object reference not set to an instance of an object
- Previous by thread: Abstract Usercontrols
- Next by thread: Re: Dynamically loading user control into Placeholder gives Object reference not set to an instance of an object
- Index(es):
Relevant Pages
|