asp.net 2005, LoadControl question...

  • Thread starter Thread starter Andrew Taylor
  • Start date Start date
A

Andrew Taylor

I have created a user control (ascx) called MyButton with a code
behind file.

I also have a main page (aspx) with a code behind file.

I want to do something like this in the main page


void Page_Load(object sender, EventArgs e)
{
MyButton button = new MyButton();
// or MyButton button = LoadControl("MyButton.ascx");
button.Text = "HI";
placeHolder.Controls.Add(button);
}

Button the MyButton class does not show up with intellisense. Since
there is not build command anymore for web projects, is it because it
is not build ? Could it be namespace related, it seems all namespace
entries are gone as well ?

-- Thanks, Andrew Taylor
 
Hi,

1) regarding namespace: if you working with "place code with separate
file" you will see Namespace. Otherwise namespace declared in the class
create for page in page compilation phase.

2) due to the fact that that every page might end up with dedicate
assembly (not as ASP.NET 1.X that all pages code behinds compile to same
DLL) you need to use <@ reference .. %> Directive in order to get
UserControl intellisense ...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Back
Top