re:
<%@ Page Language="VB" Explicit="True" Inherits="ShopCB" %>
but when I run the app, I get the following error:
could not load type 'ShopCB'.
pointing to the above Page directive.
You're missing the CodeFile reference for ASP.NET 2.0 :
Basic syntax differences between ASP.NET 1.1 and ASP.NET 2.0 :
a. ASP.NET 1.1 page definition
a. <%@ page codeBehind="webform1.aspx.cs" inherits="WebForm1" %>
b. ASP.NET 1.1 code-behind class definition
a. public class WebForm1 : System.Web.UI.Page
c. ASP.NET 2.0 page definition
a. <%@ page codeFile="webform1.aspx.cs" inherits="WebForm1" %>
d. ASP.NET 2.0 code-behind class definition
a. public partial class WebForm1 : System.Web.UI.Page
Juan T. Llibre, asp.net MVP
asp.net faq :
http://asp.net.do/faq/
foros de asp.net, en español :
http://asp.net.do/foros/
=======================================
<rn**@rediffmail.comwrote in message news:11*********************@m7g2000cwm.googlegrou ps.com...
There's your problem.
The App_Code directory is not meant to be a repository for code-behind.
It's only a repository for helper classes.
Put your code-behind sources in the same directory as your page sources.
Or...compile to a DLL and don't use the source code-behind at all.
Juan, as per your advice, I removed all the code behind files from the
App_Code directory & relocated them to the directory that houses the
page sources but it's causing problems. Assume that an ASPX page, named
Shop.aspx, resides in C:\Inetpub\wwwroot\ASPX\Shop. I cut the code
behind of Shop.aspx named Shop.aspx.vb from
C:\Inetpub\wwwroot\ASPX\Shop\App_Code & pasted it in
C:\Inetpub\wwwroot\ASPX\Shop directory. The public class in
Shop.aspx.vb is named ShopCB. I added the Inherits attribute to the
Page directive in Shop.aspx like this:
<%@ Page Language="VB" Explicit="True" Inherits="ShopCB" %>
but when I run the app, I get the following error:
Could not load type 'ShopCB'.
pointing to the above Page directive.
Shop.aspx.vb also imports a few user-defined namespaces. For e.g. there
is a class file named MyShop.vb (which is a helper class) in the
App_Code directory which has the namespace NSShop. There is a line in
Shop.aspx.vb which imports this namespace NSShop using the following
line.
Imports NSShop
When I try to compile Shop.aspx.vb into a DLL, I get the following
error:
Namespace or type specified in the Imports 'NSShop' doesn't contain any
public member or cannot be found. Make sure the namespace or the type
is defined and contains at least one public member. Make sure the
imported element name doesn't use any aliases.
I am sure that the namespace NSShop exists because when I type the word
"Imports" followed by a space in Shop.aspx.vb, then intellisense lists
NSShop as one of the namespaces. So I am sure the namespace NSShop
exists. Moreover namespace NSShop does contain public members (in fact,
more than one). I am not using any aliases as well. So why am I
encountering this error when I am trying to compile Shop.aspx.vb?
Note that if I relocate Shop.aspx.vb in the App_Code directory, then
the app works fine without any problems.
This is really driving me nuts.....
Juan T. Llibre wrote:
re:
the entire logic resides in a code behind named
MyUC.ascx.vb which exists in the App_Code directory
There's your problem.
The App_Code directory is not meant to be a repository for code-behind.
It's only a repository for helper classes.
Put your code-behind sources in the same directory as your page sources.
Or...compile to a DLL and don't use the source code-behind at all.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<rn**@rediffmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Is putting a VB class file in the special directory named App_Code the
same as relocating the VB class file from the App_Code directory to
another directory & then using the VBC tool, compiling the VB class
file into a DLL & putting the DLL in the bin directory?
Though while running an ASP.NET app using either of the 2 approaches
doesn't make any difference, Visual Web Developer 2005 Express Edition
behaves erratically sometimes if the VB class file resides in the
App_Code directory & the corresponding DLL doesn't exist in the bin
directory.
I have a user control named MyUC.ascx. This file only contains the UI
elements (like TextBoxes, Labels etc.) & the entire logic resides in a
code behind named MyUC.ascx.vb which exists in the App_Code directory.
I register the user control in an ASPX page named MyPage.aspx (which
resides outside the App_Code directory) with the following Register
directive
<%@ Register TagPrefix="UC" TagName="UCtrl" Src="MyUC.ascx" %>
& add the following lines after the Register directive:
<script runat="server">
Public UC1 As MyUC_ascx
Public UC2 As MyUC_ascx
Sub Page_Load(....)
'some code
End Sub
</script>
Now when the mouse is hovered over any of the 2 lines which declare the
2 variables UC1 & UC2 (the 2 "Public" lines) in VWD, then VWD says
Type 'MyUC_ascx' is not declared.
But if I relocate the code behind MyUC.ascx.vb to some directory other
than the App_Code directory & then compile MyUC.ascx.vb into a DLL in
the bin directory using VBC, then VWD no longer reflects the error when
the mouse is moved over the 2 lines which declare UC1 & UC2.
Is this some sort of bug in VWD or does the CLR behave differently when
a VB class file resides in the App_Code directory (& no corresponding
DLL exists in the bin directory) and when the VB class does not reside
in the App_Code directory & the VB class file is compiled into a DLL in
the bin directory?