Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Added User Control

Status
Not open for further replies.

JenJen

Programmer
Joined
Sep 24, 2002
Messages
10
Location
GB
I have a solution with 2 projects in it. I need to programatically add a user control from one project into the other one (as you cannot declare this normally on the form because it is in a different application). When the page_load event of the user control is fired at run-time, none of the form objects on the user control exist.

Is this a namespace issue? Or can you just not share a user control over 2 projects without having a copy in both projects.


 
Do you have a refernce to the project that holds the UC that you need?
 
Yes, it all compiles fine, and the page_load event is fired. But any reference to the form objects in the UC gives the error - Object reference not set to an instance of an object.
The line of code that errors is trying to add the imageurl of an image.

Thanks,
Jenni
 
Can you show the code that gives the error, and the HTML of the UC?
 
HTML in user control -
Code:
<asp:image Height="33" AlternateText="Powered by WorldPay" Width="139" ImageAlign="AbsMiddle" Runat="server" ID="imageWorldPay"></asp:image>

Code that gives the error in the code behind of the UC -
Code:
imageWorldPay.ImageUrl = "~/images/poweredbyworldpay.gif";

Code in the other project which loads the uc -
Code:
protected System.Web.UI.Control pricegridcontrol;
pricegridcontrol = new LumleyJacobsSharedLibrary.controls.BuyingProcessPriceGrid();
wlnav_pricegrid.Controls.Add(pricegridcontrol);

Thanks,
Jenni

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top