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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LoadControl missing?

Status
Not open for further replies.

tbrentlong

Programmer
Apr 22, 2003
5
US
I need to programatically load a control so that I can set properties and have it rendered appropriately. However, when I attempt to LoadControl, I get the following error:

"An object reference is required for the nonstatic field, method, or property
'System.Web.UI.TemplateControl.LoadControl(string)'

//the line:
protected Header ucHeader = (Header)LoadControl("uc/Header.ascx");

Any suggestions?
 
I found the solution.

I was attempting to assign the control outside of a method. Oddly enough, this works in another app that I did using VB. I changed the line as shown below and moved the assignment inside of Page_Load:

protected Header ucHeader;

private void Page_Load(....)
{
ucHeader = (Header)LoadControl("uc/Header.ascx");
}

Strange. Hope this helps someone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top