Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting namespace name not found for ASP.net user control

So I'm having problems when I try to publish the website. I'm in visual studio 2008 sp1.

I've got a bunch of user controls and on a few pages I'm using them programatically.

I've got a reference on the aspx page

<%@ Reference Control="~/UserControls/Foo.ascx" %>

Then on the code behing I use

ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");

If I navigate to the page it works fine, but when I goto publish the website I get a compile time error.

like image 705
Joel Barsotti Avatar asked Dec 31 '22 00:12

Joel Barsotti


2 Answers

Argh, I'm bleeding development hours on this same issue. Does anyone have a solution to this ?

BTW: It builds if you uncheck "Allow this precompiled site to be updatable" (Right-click on the website, choose Property Pages, MSBuild Option)

But I need the site to be updatable.

like image 85
Riaz Hosein Avatar answered Jan 20 '23 21:01

Riaz Hosein


I had this same problem - actually, in my case I could get it to compile and build my website, but it would blow up spectacularly when doing an automated build.

Try replacing your code as follows:

ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");

with

USERCONTROLS_Foo newFoo control = (USERCONTROLS_Foo)Page.LoadControl("~/UserControls/Foo.ascx");

(Capitalization will be based on how you capitalized your directory name/control name - but in either case should highlight appropriately).

like image 21
Bob Palmer Avatar answered Jan 20 '23 20:01

Bob Palmer