473,605 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot get a handle on web UserControls in ASP 2.0

I'm converting some ASP web projects from VS 2003 to VS2005/ASP 2.0. The
worst problem I've run into is all references (in codebehind CS files) to
UserControls fail.

I get the error "The type or namespace 'MyUserControl' does not exist in the
namespace 'The.Correct.Na mespace' (are you missing an assembly reference?)"
even though the user control in question is named 'MyUserControl' and is
explicitly wrapped in the namespace block 'namespace The.Correct.Nam eSpace
{'. And, obviously, it worked in the previous framework so it's not a typo.

Is there an approach for overcoming this conversion issue?

Thank you.

Greg Smalter
Nov 19 '05 #1
11 1299
The verbiage in the page directive has changed in beta 2. This article [1]
may help. What bothers me is there does not appear to be a central location
where changes have been documented. This of course is FUBAR.

I'm going to post to MSDN Product Feedback [2] and ask for a centralized
page or blog that tracks changes and ask you to do the same

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee. com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://west-wind.com/weblog/posts/2122.aspx
[2] http://lab.msdn.microsoft.com/Produc...k/Default.aspx

"Greg Smalter" <Gr*********@di scussions.micro soft.com> wrote in message
news:84******** *************** ***********@mic rosoft.com...
I'm converting some ASP web projects from VS 2003 to VS2005/ASP 2.0. The
worst problem I've run into is all references (in codebehind CS files) to
UserControls fail.

I get the error "The type or namespace 'MyUserControl' does not exist in
the
namespace 'The.Correct.Na mespace' (are you missing an assembly
reference?)"
even though the user control in question is named 'MyUserControl' and is
explicitly wrapped in the namespace block 'namespace The.Correct.Nam eSpace
{'. And, obviously, it worked in the previous framework so it's not a
typo.

Is there an approach for overcoming this conversion issue?

Thank you.

Greg Smalter

Nov 19 '05 #2
That explains a little about how the compilation models are different, but it
doesn't mention namespaces or how to address a transition. Good information
though, thanks.

I still need a way to make my existing ASP 1.1 framework web sites work in
ASP 2.0 by resolving this namespace issue and getting a handle on control
classes. It seems possible, because if I create a new web site and create a
control loose in the root, I can access it statically from the default page.
But if I create it in a folder, I can't. And there's no way for me to find
out what namespace it's using for the control in the folder, either. I need
to be able to statically access control classes no matter where they are,
like I used to.

Thank you.

Greg Smalter

"clintonG" wrote:
The verbiage in the page directive has changed in beta 2. This article [1]
may help. What bothers me is there does not appear to be a central location
where changes have been documented. This of course is FUBAR.

I'm going to post to MSDN Product Feedback [2] and ask for a centralized
page or blog that tracks changes and ask you to do the same

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee. com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://west-wind.com/weblog/posts/2122.aspx
[2] http://lab.msdn.microsoft.com/Produc...k/Default.aspx

"Greg Smalter" <Gr*********@di scussions.micro soft.com> wrote in message
news:84******** *************** ***********@mic rosoft.com...
I'm converting some ASP web projects from VS 2003 to VS2005/ASP 2.0. The
worst problem I've run into is all references (in codebehind CS files) to
UserControls fail.

I get the error "The type or namespace 'MyUserControl' does not exist in
the
namespace 'The.Correct.Na mespace' (are you missing an assembly
reference?)"
even though the user control in question is named 'MyUserControl' and is
explicitly wrapped in the namespace block 'namespace The.Correct.Nam eSpace
{'. And, obviously, it worked in the previous framework so it's not a
typo.

Is there an approach for overcoming this conversion issue?

Thank you.

Greg Smalter


Nov 19 '05 #3
Clinton,

I think that what you're requesting was published
at MSDN in November 2004 :

http://msdn.microsoft.com/asp.net/wh...ta2update.aspx

The centralized page for ASP.NET Beta 2 information is at :

http://msdn.microsoft.com/asp.net/beta2/default.aspx

Bookmark it.

I go there at least weekly to get up to speed with changes/features.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com > wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
The verbiage in the page directive has changed in beta 2. This article [1] may help.
What bothers me is there does not appear to be a central location where changes have
been documented. This of course is FUBAR.

I'm going to post to MSDN Product Feedback [2] and ask for a centralized page or blog
that tracks changes and ask you to do the same

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee. com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://west-wind.com/weblog/posts/2122.aspx
[2] http://lab.msdn.microsoft.com/Produc...k/Default.aspx

"Greg Smalter" <Gr*********@di scussions.micro soft.com> wrote in message
news:84******** *************** ***********@mic rosoft.com...
I'm converting some ASP web projects from VS 2003 to VS2005/ASP 2.0. The
worst problem I've run into is all references (in codebehind CS files) to
UserControls fail.

I get the error "The type or namespace 'MyUserControl' does not exist in the
namespace 'The.Correct.Na mespace' (are you missing an assembly reference?)"
even though the user control in question is named 'MyUserControl' and is
explicitly wrapped in the namespace block 'namespace The.Correct.Nam eSpace
{'. And, obviously, it worked in the previous framework so it's not a typo.

Is there an approach for overcoming this conversion issue?

Thank you.

Greg Smalter


Nov 19 '05 #4
The article basically mentions the changes necessary to the markup, which the
Visual Studio 2005 project upgrade utility has already done for me. It
doesn't mention namespaces at all. But it's a good article, thanks.

I'll try to describe the problem a little differently. I have a project in
which .cs files (not code-behind) existed in the same namespace as .ascx.cs
files (codebehinds for user controls). After upgrading to ASP 2.0, I have
access to the namespace, but only to the non-codebehind elements in it. None
of the classes that exist in codebehind files show up. It's as if they are
no longer part of the namespace, even though the namespace is explicitly
defined in those codebehind files (as was always the case in ASP 1.1).

I need a way to statically access classes and their static methods that
exist in user control codebehind files from other user control codebehind
files and from loose .cs code files, as was possible in ASP 1.1.

Thank you.

Greg Smalter.

"Juan T. Llibre" wrote:
Clinton,

I think that what you're requesting was published
at MSDN in November 2004 :

http://msdn.microsoft.com/asp.net/wh...ta2update.aspx

Nov 19 '05 #5
Hi Greg:

Unfortunately, this scenario has gotten insanely complex in 2.0, at
least as of beta 2. The problem is not a namespace issue, but a "which
assembly to reference" issue because web "projects" are no longer
projects.

Each web form, and each user control can compile into a single
assembly - think of each web form and each user control as a separate
class library project. An island unto themselves.

These posts might shed some insight:
http://odetocode.com/Blogs/scott/arc...6/30/1889.aspx
http://odetocode.com/Blogs/scott/arc...6/29/1882.aspx

To establish assembly references between pages and user controls
you'll need an @ Reference directive with a VirtualPath attribute
pointing to the control you want to reference.

Getting to a user control from a loose .cs file, which I assume is in
App_Code, is a bit more difficult. You'll need to define a 'stub'
class in App_Code for the user control. That is a class that your
UserControl class will then inherit from - this is the only way to
access ASPX/ASCX code from App_Code. In post beta 2 the runtime will
generate stub classes for you.

All of this complexity exists for people who like to randomly drop
files into a web application and have it just work...

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 4 Jul 2005 05:12:01 -0700, Greg Smalter
<Gr*********@di scussions.micro soft.com> wrote:
The article basically mentions the changes necessary to the markup, which the
Visual Studio 2005 project upgrade utility has already done for me. It
doesn't mention namespaces at all. But it's a good article, thanks.

I'll try to describe the problem a little differently. I have a project in
which .cs files (not code-behind) existed in the same namespace as .ascx.cs
files (codebehinds for user controls). After upgrading to ASP 2.0, I have
access to the namespace, but only to the non-codebehind elements in it. None
of the classes that exist in codebehind files show up. It's as if they are
no longer part of the namespace, even though the namespace is explicitly
defined in those codebehind files (as was always the case in ASP 1.1).

I need a way to statically access classes and their static methods that
exist in user control codebehind files from other user control codebehind
files and from loose .cs code files, as was possible in ASP 1.1.

Thank you.

Greg Smalter.

"Juan T. Llibre" wrote:
Clinton,

I think that what you're requesting was published
at MSDN in November 2004 :

http://msdn.microsoft.com/asp.net/wh...ta2update.aspx


Nov 19 '05 #6
Hi, Greg.

re:
None of the classes that exist in codebehind files show up.
That's strange. They do show up for me.

In my vb source ( sorry for using VB, but it should work the same for C# )
I have the following :

Namespace ObjetoDatosVB
Public Class RegistrosSQL
etc...

When I open my aspx file to work on it, and place
<%@ Import Namespace="Obje toDatosVB" %>
at the top of my aspx, and then write

Dim RS as New

and hit the space bar, the available classes show up
and RegistrosSQL is available and is filled in by Intellisense.

Are your *.cs files in the App_Code directory ?

That's the only place where VS.NET Beta 2 will recognize them.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Greg Smalter" <Gr*********@di scussions.micro soft.com> wrote in message
news:3C******** *************** ***********@mic rosoft.com... The article basically mentions the changes necessary to the markup, which the
Visual Studio 2005 project upgrade utility has already done for me. It
doesn't mention namespaces at all. But it's a good article, thanks.

I'll try to describe the problem a little differently. I have a project in
which .cs files (not code-behind) existed in the same namespace as .ascx.cs
files (codebehinds for user controls). After upgrading to ASP 2.0, I have
access to the namespace, but only to the non-codebehind elements in it. None
of the classes that exist in codebehind files show up. It's as if they are
no longer part of the namespace, even though the namespace is explicitly
defined in those codebehind files (as was always the case in ASP 1.1).

I need a way to statically access classes and their static methods that
exist in user control codebehind files from other user control codebehind
files and from loose .cs code files, as was possible in ASP 1.1.

Thank you.

Greg Smalter.

"Juan T. Llibre" wrote:
Clinton,

I think that what you're requesting was published
at MSDN in November 2004 :

http://msdn.microsoft.com/asp.net/wh...ta2update.aspx


Nov 19 '05 #7
Hi, Scott.

re:
---000---
Getting to a user control from a loose .cs file, which I assume is in
App_Code, is a bit more difficult. You'll need to define a 'stub'
class in App_Code for the user control. That is a class that your
UserControl class will then inherit from - this is the only way to
access ASPX/ASCX code from App_Code.
---000---

I'll agree 100% with you if you limit the comments to ASCX code.

As explained in my previous reply, there's no problem in getting
Intellisense to recognize "standard" code-behind in class files,
as long as they are placed in the App_Code directory and the
Namespace is referenced with an Imports statement in the ASPX page.

I.O.W., accessing classes and their static methods that exist in user control
codebehind files needs the stubs or an @ Reference directive with a
VirtualPath attribute pointing to the control you want to reference,
as you well explain, but classes in "loose .cs code files" show up without
anything being required but placing them in the App_Code directory and
referencing the Namespace.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Scott Allen" <sc***@nospam.o detocode.com> wrote in message
news:1b******** *************** *********@4ax.c om...
Hi Greg:

Unfortunately, this scenario has gotten insanely complex in 2.0, at
least as of beta 2. The problem is not a namespace issue, but a "which
assembly to reference" issue because web "projects" are no longer
projects.

Each web form, and each user control can compile into a single
assembly - think of each web form and each user control as a separate
class library project. An island unto themselves.

These posts might shed some insight:
http://odetocode.com/Blogs/scott/arc...6/30/1889.aspx
http://odetocode.com/Blogs/scott/arc...6/29/1882.aspx

To establish assembly references between pages and user controls
you'll need an @ Reference directive with a VirtualPath attribute
pointing to the control you want to reference.

Getting to a user control from a loose .cs file, which I assume is in
App_Code, is a bit more difficult. You'll need to define a 'stub'
class in App_Code for the user control. That is a class that your
UserControl class will then inherit from - this is the only way to
access ASPX/ASCX code from App_Code. In post beta 2 the runtime will
generate stub classes for you.

All of this complexity exists for people who like to randomly drop
files into a web application and have it just work...

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 4 Jul 2005 05:12:01 -0700, Greg Smalter
<Gr*********@di scussions.micro soft.com> wrote:
The article basically mentions the changes necessary to the markup, which the
Visual Studio 2005 project upgrade utility has already done for me. It
doesn't mention namespaces at all. But it's a good article, thanks.

I'll try to describe the problem a little differently. I have a project in
which .cs files (not code-behind) existed in the same namespace as .ascx.cs
files (codebehinds for user controls). After upgrading to ASP 2.0, I have
access to the namespace, but only to the non-codebehind elements in it. None
of the classes that exist in codebehind files show up. It's as if they are
no longer part of the namespace, even though the namespace is explicitly
defined in those codebehind files (as was always the case in ASP 1.1).

I need a way to statically access classes and their static methods that
exist in user control codebehind files from other user control codebehind
files and from loose .cs code files, as was possible in ASP 1.1.

Thank you.

Greg Smalter. "Juan T. Llibre" wrote:
Clinton,

I think that what you're requesting was published
at MSDN in November 2004 :

http://msdn.microsoft.com/asp.net/wh...ta2update.aspx

Nov 19 '05 #8
I think we're talking about opposite problems. You are illustrating that you
can access code files (non-codebehind) from an aspx page. My problem is that
I cannot access my aspx (or ascx) (codebehind) classes from a code file.

"Juan T. Llibre" wrote:
Hi, Greg.

re:
None of the classes that exist in codebehind files show up.


That's strange. They do show up for me.

In my vb source ( sorry for using VB, but it should work the same for C# )
I have the following :

Namespace ObjetoDatosVB
Public Class RegistrosSQL
etc...

When I open my aspx file to work on it, and place
<%@ Import Namespace="Obje toDatosVB" %>
at the top of my aspx, and then write

Dim RS as New

and hit the space bar, the available classes show up
and RegistrosSQL is available and is filled in by Intellisense.

Are your *.cs files in the App_Code directory ?

That's the only place where VS.NET Beta 2 will recognize them.

Nov 19 '05 #9
Ok...
It did sound a bit too simple of a problem... ;-)

Have you bugged that at the Feedback Center ?

http://lab.msdn.microsoft.com/produc...k/Default.aspx


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Greg Smalter" <Gr*********@di scussions.micro soft.com> wrote in message
news:A8******** *************** ***********@mic rosoft.com...
I think we're talking about opposite problems. You are illustrating that you
can access code files (non-codebehind) from an aspx page. My problem is that
I cannot access my aspx (or ascx) (codebehind) classes from a code file.

"Juan T. Llibre" wrote:
Hi, Greg.

re:
>None of the classes that exist in codebehind files show up.


That's strange. They do show up for me.

In my vb source ( sorry for using VB, but it should work the same for C# )
I have the following :

Namespace ObjetoDatosVB
Public Class RegistrosSQL
etc...

When I open my aspx file to work on it, and place
<%@ Import Namespace="Obje toDatosVB" %>
at the top of my aspx, and then write

Dim RS as New

and hit the space bar, the available classes show up
and RegistrosSQL is available and is filled in by Intellisense.

Are your *.cs files in the App_Code directory ?

That's the only place where VS.NET Beta 2 will recognize them.

Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1432
by: Emma | last post by:
Hi, I'm developing a GUI with almost all Usercontrols. It's been working wonderfull up till a few weeks ago, and really crashed yesterday. Suddenly I can no longer add some of my usercontrols to any of the others (I've also tried to create new usercontrols and windowforms and add them to the new control, but that doesn't work any better). It's really frustrating since I've been able to add them and run the program before.
1
1075
by: DKode | last post by:
I have been researching a couple of different ways to accomplish a master "Template" page, usually being default.aspx or index.aspx that holds the repeating content of the site. Most of the postings i've come across say they have a main page, and all the subpages they create as a UserControl. i.e.: index.ascx, contact.ascx and then by using a unique query string, they call the usercontrols into the main page. i.e.:...
4
1640
by: Anders K. Jacobsen [DK] | last post by:
Hi I have some common UserControls i want to share between to sites (on the same mashine but on diffrent virtual paths). right now i have on solution file with aprox 10 projects. 2 of these is webprojetcs wich need to shere some common userControls. Optimally i want a class libarary project wich contains the controls so i could import the DLL and use the controls. But that of course doesnt work.
3
1575
by: navyliu | last post by:
I have raised a discussion about assembly unloading.But we can't get a final solution. Since we cannot unlaod a assembly,Is there any reference about this indicate that this problem won't make smartclient use up memory? Best regard navyliu
4
1250
by: Nathan Sokalski | last post by:
In several of my UserControls I add properties. If I access these properties in the CodeBehind of the pages that use the controls, I recieve an error when compiling. The reason for this is because the compiler tries to compile the pages that use the UserControls before compiling the UserControls, and therefore does not know that the property exists when compiling. The only way around this that I have found is to use the CType() function as...
0
923
by: Jeremy Kitchen | last post by:
Hello, I am using a two derived user controls and I recieved this error message when handleing the DragDrop Event of the base class's TreeView Control. The only effect I have noticed is that I cannot use the designer view for the two derived classes. I can however see the usercontrols in the designer view of Controls and forms that use them. Does anyone know what the error message means?
2
596
by: Jonathan Boivin | last post by:
Hi people, Let me introduce to how I get this error. I have a form which load all my bills representation depending upon filters which each bill is a usercontrol of my own having some textboxes containing bill's datas. (I already replaced the labels by painting the text instead.) When I click on my filter button, it clears the current usercontrol bills and load the new ones upon the current chosen filters. The bug happens when
1
1677
by: =?Utf-8?B?RGFuaWVsIERpVml0YQ==?= | last post by:
First, I am using VS2005 with windows XP. I am having an issue where I cannot see the images in my usercontrols or the ASPX pages they are dropped onto (the ASPX pages are on the root of the site for now). Indies my user control I am using a standard html img tag: <img src="/images/imageName.jpg" alt="" title="Test"/> Here is the path structure c:\websites\NewSite Under NewSite we have these folders Images UserControls
7
2129
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows CType(Me.FindControl("admin" & CStr(section("buttontext")).Replace(" ", "")), adminsection2).RefreshSection() Next End Sub
0
8418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1271
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.