2 or more partial classes and an aspx file in asp.net 2.0

G

Guest

Hi

In asp.net 2.0 an aspx files .cs file is a partial class and all works fine,
however,
I thought I’d be able to create another class file, call it a partial class
and have
that compile and load as a 3rd partial class. This would be handy so i can
generate
standard code into one of the partial classes, while having my custom code
untouched
by the code generator.

However, when i try this, the 3rd .cs file doesn't even seem to compile, and
any
methods contained therein are not visible by the 1st .cs file, or anything
else
for that matter.

If I try 3 partial classes that aren’t part of an aspx then things work as
expected.

So I have 3 files...

Default.aspx
Default.aspx.cs
Default_.aspx.cs

Default.aspx and Default.aspx.cs interact as expected.

Default.aspx.cs and Default_aspx.cs both implement partial class Default:
System.Web.UI.Page

like so...

Default.aspx.cs

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TestMethod();
}
}

Default_.aspx.cs

public partial class _Default : System.Web.UI.Page
{
public bool TestMethod()
{
return true;
}
}

When i compile the project i get the following error:
Error 1 The name 'TestMethod' does not exist in the current context
C:\Documents and Settings\petert\My Documents\Visual Studio
2005\WebSites\WebSite2\Default.aspx.cs
15 9 C:\...\WebSite2\

If i have a non aspx class, with three parts like so...

Class1.cs
Class1_.cs
Class1__.cs

public partial class Class1
{
public Class1()
{
TestMethod1();
TestMethod2();
}
}

public partial class Class1
{
public bool TestMethod1()
{
return true;
}
}

public partial class Class1
{
public bool TestMethod2()
{
return true;
}
}

All compile and work as expected.

I this a limitation with aspx files, or am I missing something.

If there is a specific asp.net 2.0 newsgroup then apologies, and please
direct me to it.

Also, is there a specific newgroup for asp.net 2.0 / vs2005 issues ?
 
B

Bruce Barker

the problem is there is no way to tell the asp.net compiler to include the
third file with an aspx page. each page is built into its own dll, the aspx
page has in the page directive then name of the codebehind file (see
CodeFile=""), so the two files are compiled into the same assembly.

the files in app_code dir are all compiled into one assembly, so you can use
3 files here.


-- bruce (sqlwork.com)
 
G

Guest

This doesn't fix the problem.
I still get the error that the test method doesnt exist in the current
context.
 
G

Guest

So it can't be done. ?



Bruce Barker said:
the problem is there is no way to tell the asp.net compiler to include the
third file with an aspx page. each page is built into its own dll, the aspx
page has in the page directive then name of the codebehind file (see
CodeFile=""), so the two files are compiled into the same assembly.

the files in app_code dir are all compiled into one assembly, so you can use
3 files here.


-- bruce (sqlwork.com)
 
G

Guest

i tried your suggestion, but i still get the same error whenever i try to
reference the method from the aspx.cs page.

Also, i don't see an attachment ?

Could you attach or post the working code + specify the location where each
file should sit ?

Thanks alot for your time so far.
 
S

Steven Cheng[MSFT]

Hi Ptass,

I Agree with Bruce's explanation. For ASPX page, their page class's partial
class file are particualrly specified through the "codeFile" attribute in
@Page directive. Also, the source files in App_Code folder will be compiled
into different assemlies with the Page class's assembly, and the dynamic
compilation time and sequence are also different. So manually provide
additional partial class file for aspx page is not supported naturally.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)




--------------------
| Thread-Topic: 2 or more partial classes and an aspx file in asp.net 2.0
| thread-index: AcXmVUDxW9ivrTZTQjiHYYD7b71cCQ==
| X-WBNR-Posting-Host: 203.58.99.1
| From: "=?Utf-8?B?cHRhc3M=?=" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: 2 or more partial classes and an aspx file in asp.net 2.0
| Date: Thu, 10 Nov 2005 16:17:08 -0800
| Lines: 127
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:357230
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| So it can't be done. ?
|
|
|
| "Bruce Barker" wrote:
|
| > the problem is there is no way to tell the asp.net compiler to include
the
| > third file with an aspx page. each page is built into its own dll, the
aspx
| > page has in the page directive then name of the codebehind file (see
| > CodeFile=""), so the two files are compiled into the same assembly.
| >
| > the files in app_code dir are all compiled into one assembly, so you
can use
| > 3 files here.
| >
| >
| > -- bruce (sqlwork.com)
| >
| >
| >
| >
| > | > > Hi
| > >
| > > In asp.net 2.0 an aspx files .cs file is a partial class and all
works
| > > fine,
| > > however,
| > > I thought I'd be able to create another class file, call it a partial
| > > class
| > > and have
| > > that compile and load as a 3rd partial class. This would be handy so
i can
| > > generate
| > > standard code into one of the partial classes, while having my custom
code
| > > untouched
| > > by the code generator.
| > >
| > > However, when i try this, the 3rd .cs file doesn't even seem to
compile,
| > > and
| > > any
| > > methods contained therein are not visible by the 1st .cs file, or
anything
| > > else
| > > for that matter.
| > >
| > > If I try 3 partial classes that aren't part of an aspx then things
work as
| > > expected.
| > >
| > > So I have 3 files...
| > >
| > > Default.aspx
| > > Default.aspx.cs
| > > Default_.aspx.cs
| > >
| > > Default.aspx and Default.aspx.cs interact as expected.
| > >
| > > Default.aspx.cs and Default_aspx.cs both implement partial class
Default:
| > > System.Web.UI.Page
| > >
| > > like so...
| > >
| > > Default.aspx.cs
| > >
| > > public partial class _Default : System.Web.UI.Page
| > > {
| > > protected void Page_Load(object sender, EventArgs e)
| > > {
| > > TestMethod();
| > > }
| > > }
| > >
| > > Default_.aspx.cs
| > >
| > > public partial class _Default : System.Web.UI.Page
| > > {
| > > public bool TestMethod()
| > > {
| > > return true;
| > > }
| > > }
| > >
| > > When i compile the project i get the following error:
| > > Error 1 The name 'TestMethod' does not exist in the current context
| > > C:\Documents and Settings\petert\My Documents\Visual Studio
| > > 2005\WebSites\WebSite2\Default.aspx.cs
| > > 15 9 C:\...\WebSite2\
| > >
| > > If i have a non aspx class, with three parts like so...
| > >
| > > Class1.cs
| > > Class1_.cs
| > > Class1__.cs
| > >
| > > public partial class Class1
| > > {
| > > public Class1()
| > > {
| > > TestMethod1();
| > > TestMethod2();
| > > }
| > > }
| > >
| > > public partial class Class1
| > > {
| > > public bool TestMethod1()
| > > {
| > > return true;
| > > }
| > > }
| > >
| > > public partial class Class1
| > > {
| > > public bool TestMethod2()
| > > {
| > > return true;
| > > }
| > > }
| > >
| > > All compile and work as expected.
| > >
| > > I this a limitation with aspx files, or am I missing something.
| > >
| > > If there is a specific asp.net 2.0 newsgroup then apologies, and
please
| > > direct me to it.
| > >
| > > Also, is there a specific newgroup for asp.net 2.0 / vs2005 issues ?
| >
| >
| >
|
 
J

Juan T. Llibre

re:
And un naturally :) ?

Read Steven's comment as follows :
manually providing an additional partial class file
for an aspx page is not supported, naturally.
re:
ie., Is there a workaround ?

No, there isn't.
You can't have two code-behind files for one aspx page.

What you *can* do is :

1. Write utility classes and compile *them* into
assemblies which you can reference in your aspx pages.

This is the way I prefer to handle this need.

2. Use the App_Code folder as a repository for partial classes.
You can place many partial class definitions in separate files in App_Code.
They will all be compiled into a single class.
 
S

Steven Cheng[MSFT]

Hi Ptass,

Thanks for your response. I'm afraid using Multiple partial class files for
aspx page is not allowed due to the fixed page compilation model. However,
we can alternatively provide a common base page class for our pages'
codebehind class. For example, all the pages which will share some common
functionalities can use one central base page class. Let's call it
"CommonBasePage", then, let all those pages' code behind class inherit from
this common class so that this class's non-private functions can be shared
by those concrete classes. Also, in asp.net 2.0, there is one new
attribute named "CodeFileBaseClass", we can define our common base page 's
class through this attribute, so that the runtime will be able to
dynamically compiled the page's structure and make the Controls references
in concrete pages also available in common base class. For example, here is
an example which use this attribute:


=====common base page class(in App_Code)=========

public partial class CommonBasePage : System.Web.UI.Page
{
protected Label Label1;

public CommonBasePage()
{}

protected virtual void Page_Load(object sender, EventArgs e)
{

Label1.Text = SayHello();
}

public string SayHello()
{
return "Hello CommonBasePage.";
}

}
===========================================

======concrete page aspx==========
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageOne.aspx.cs"
Inherits="CommonPage_PageOne"
CodeFileBaseClass="CommonBasePage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label></div>
</form>
</body>
</html>
===============================

=====concrete page code behind==========
public partial class CommonPage_PageOne : CommonBasePage
{

}

=====================

We can see that the Label1 control in concrete page can also be accessible
in base page as long as we define the control reference......

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)













--------------------
| From: "Juan T. Llibre" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: 2 or more partial classes and an aspx file in asp.net 2.0
| Date: Mon, 14 Nov 2005 05:17:19 -0400
| Lines: 192
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 222stb33.codetel.net.do 64.32.114.222
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:357857
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| re:
| > And un naturally :) ?
|
| Read Steven's comment as follows :
| > manually providing an additional partial class file
| > for an aspx page is not supported, naturally.
|
| re:
| >ie., Is there a workaround ?
|
| No, there isn't.
| You can't have two code-behind files for one aspx page.
|
| What you *can* do is :
|
| 1. Write utility classes and compile *them* into
| assemblies which you can reference in your aspx pages.
|
| This is the way I prefer to handle this need.
|
| 2. Use the App_Code folder as a repository for partial classes.
| You can place many partial class definitions in separate files in
App_Code.
| They will all be compiled into a single class.
|
|
|
|
|
| Juan T. Llibre, ASP.NET MVP
| ASP.NET FAQ : http://asp.net.do/faq/
| ASPNETFAQ.COM : http://www.aspnetfaq.com/
| Foros de ASP.NET en Español : http://asp.net.do/foros/
| ======================================
| | > And un naturally :) ? ie., Is there a workaround ?
| >
| > "Steven Cheng[MSFT]" wrote:
| >
| >> Hi Ptass,
| >>
| >> I Agree with Bruce's explanation. For ASPX page, their page class's
partial
| >> class file are particualrly specified through the "codeFile" attribute
in
| >> @Page directive. Also, the source files in App_Code folder will be
compiled
| >> into different assemlies with the Page class's assembly, and the
dynamic
| >> compilation time and sequence are also different. So manually provide
| >> additional partial class file for aspx page is not supported naturally.
| >>
| >> Thanks,
| >>
| >> Steven Cheng
| >> Microsoft Online Support
|
|
| >> | So it can't be done. ?
| >> |
| >> | "Bruce Barker" wrote:
| >> |
| >> | > the problem is there is no way to tell the asp.net compiler to
include
| >> the
| >> | > third file with an aspx page. each page is built into its own dll,
the
| >> aspx
| >> | > page has in the page directive then name of the codebehind file
(see
| >> | > CodeFile=""), so the two files are compiled into the same assembly.
| >> | >
| >> | > the files in app_code dir are all compiled into one assembly, so
you
| >> can use
| >> | > 3 files here.
| >> | >
| >> | >
| >> | > -- bruce (sqlwork.com)
|
| >> | > | >> | > > Hi
| >> | > >
| >> | > > In asp.net 2.0 an aspx files .cs file is a partial class and all
| >> works
| >> | > > fine,
| >> | > > however,
| >> | > > I thought I'd be able to create another class file, call it a
partial
| >> | > > class
| >> | > > and have
| >> | > > that compile and load as a 3rd partial class. This would be
handy so
| >> i can
| >> | > > generate
| >> | > > standard code into one of the partial classes, while having my
custom
| >> code
| >> | > > untouched
| >> | > > by the code generator.
| >> | > >
| >> | > > However, when i try this, the 3rd .cs file doesn't even seem to
| >> compile,
| >> | > > and
| >> | > > any
| >> | > > methods contained therein are not visible by the 1st .cs file, or
| >> anything
| >> | > > else
| >> | > > for that matter.
| >> | > >
| >> | > > If I try 3 partial classes that aren't part of an aspx then
things
| >> work as
| >> | > > expected.
| >> | > >
| >> | > > So I have 3 files...
| >> | > >
| >> | > > Default.aspx
| >> | > > Default.aspx.cs
| >> | > > Default_.aspx.cs
| >> | > >
| >> | > > Default.aspx and Default.aspx.cs interact as expected.
| >> | > >
| >> | > > Default.aspx.cs and Default_aspx.cs both implement partial class
| >> Default:
| >> | > > System.Web.UI.Page
| >> | > >
| >> | > > like so...
| >> | > >
| >> | > > Default.aspx.cs
| >> | > >
| >> | > > public partial class _Default : System.Web.UI.Page
| >> | > > {
| >> | > > protected void Page_Load(object sender, EventArgs e)
| >> | > > {
| >> | > > TestMethod();
| >> | > > }
| >> | > > }
| >> | > >
| >> | > > Default_.aspx.cs
| >> | > >
| >> | > > public partial class _Default : System.Web.UI.Page
| >> | > > {
| >> | > > public bool TestMethod()
| >> | > > {
| >> | > > return true;
| >> | > > }
| >> | > > }
| >> | > >
| >> | > > When i compile the project i get the following error:
| >> | > > Error 1 The name 'TestMethod' does not exist in the current
context
| >> | > > C:\Documents and Settings\petert\My Documents\Visual Studio
| >> | > > 2005\WebSites\WebSite2\Default.aspx.cs
| >> | > > 15 9 C:\...\WebSite2\
| >> | > >
| >> | > > If i have a non aspx class, with three parts like so...
| >> | > >
| >> | > > Class1.cs
| >> | > > Class1_.cs
| >> | > > Class1__.cs
| >> | > >
| >> | > > public partial class Class1
| >> | > > {
| >> | > > public Class1()
| >> | > > {
| >> | > > TestMethod1();
| >> | > > TestMethod2();
| >> | > > }
| >> | > > }
| >> | > >
| >> | > > public partial class Class1
| >> | > > {
| >> | > > public bool TestMethod1()
| >> | > > {
| >> | > > return true;
| >> | > > }
| >> | > > }
| >> | > >
| >> | > > public partial class Class1
| >> | > > {
| >> | > > public bool TestMethod2()
| >> | > > {
| >> | > > return true;
| >> | > > }
| >> | > > }
| >> | > >
| >> | > > All compile and work as expected.
| >> | > >
| >> | > > I this a limitation with aspx files, or am I missing something.
| >> | > >
| >> | > > If there is a specific asp.net 2.0 newsgroup then apologies, and
| >> please
| >> | > > direct me to it.
| >> | > >
| >> | > > Also, is there a specific newgroup for asp.net 2.0 / vs2005
issues ?
| >> | >
| >> | >
| >> | >
| >> |
| >>
| >>
|
|
|
 
S

Steven Cheng[MSFT]

Hi Ptass,

Does the suggestion that use a common base page class in my last reply
helps? If there're still anything else we can help, please feel free to
post here.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 218109604
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Mon, 14 Nov 2005 12:08:58 GMT
| Subject: Re: 2 or more partial classes and an aspx file in asp.net 2.0
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 237
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:357887
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Hi Ptass,
|
| Thanks for your response. I'm afraid using Multiple partial class files
for
| aspx page is not allowed due to the fixed page compilation model.
However,
| we can alternatively provide a common base page class for our pages'
| codebehind class. For example, all the pages which will share some common
| functionalities can use one central base page class. Let's call it
| "CommonBasePage", then, let all those pages' code behind class inherit
from
| this common class so that this class's non-private functions can be
shared
| by those concrete classes. Also, in asp.net 2.0, there is one new
| attribute named "CodeFileBaseClass", we can define our common base page
's
| class through this attribute, so that the runtime will be able to
| dynamically compiled the page's structure and make the Controls
references
| in concrete pages also available in common base class. For example, here
is
| an example which use this attribute:
|
|
| =====common base page class(in App_Code)=========
|
| public partial class CommonBasePage : System.Web.UI.Page
| {
| protected Label Label1;
|
| public CommonBasePage()
| {}
|
| protected virtual void Page_Load(object sender, EventArgs e)
| {
|
| Label1.Text = SayHello();
| }
|
| public string SayHello()
| {
| return "Hello CommonBasePage.";
| }
|
| }
| ===========================================
|
| ======concrete page aspx==========
| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageOne.aspx.cs"
| Inherits="CommonPage_PageOne"
| CodeFileBaseClass="CommonBasePage" %>
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <html xmlns="http://www.w3.org/1999/xhtml" >
| <head runat="server">
| <title>Untitled Page</title>
| </head>
| <body>
| <form id="form1" runat="server">
| <div>
| <asp:Label ID="Label1" runat="server"
| Text="Label"></asp:Label></div>
| </form>
| </body>
| </html>
| ===============================
|
| =====concrete page code behind==========
| public partial class CommonPage_PageOne : CommonBasePage
| {
|
| }
|
| =====================
|
| We can see that the Label1 control in concrete page can also be
accessible
| in base page as long as we define the control reference......
|
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
|
|
|
|
|
|
|
|
|
|
| --------------------
| | From: "Juan T. Llibre" <[email protected]>
| | References: <[email protected]>
| <[email protected]>
| <[email protected]>
| <[email protected]>
| <[email protected]>
| | Subject: Re: 2 or more partial classes and an aspx file in asp.net 2.0
| | Date: Mon, 14 Nov 2005 05:17:19 -0400
| | Lines: 192
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| | X-RFC2646: Format=Flowed; Original
| | Message-ID: <[email protected]>
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: 222stb33.codetel.net.do 64.32.114.222
| | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl
| microsoft.public.dotnet.framework.aspnet:357857
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | re:
| | > And un naturally :) ?
| |
| | Read Steven's comment as follows :
| | > manually providing an additional partial class file
| | > for an aspx page is not supported, naturally.
| |
| | re:
| | >ie., Is there a workaround ?
| |
| | No, there isn't.
| | You can't have two code-behind files for one aspx page.
| |
| | What you *can* do is :
| |
| | 1. Write utility classes and compile *them* into
| | assemblies which you can reference in your aspx pages.
| |
| | This is the way I prefer to handle this need.
| |
| | 2. Use the App_Code folder as a repository for partial classes.
| | You can place many partial class definitions in separate files in
| App_Code.
| | They will all be compiled into a single class.
| |
| |
| |
| |
| |
| | Juan T. Llibre, ASP.NET MVP
| | ASP.NET FAQ : http://asp.net.do/faq/
| | ASPNETFAQ.COM : http://www.aspnetfaq.com/
| | Foros de ASP.NET en Español : http://asp.net.do/foros/
| | ======================================
| | | | > And un naturally :) ? ie., Is there a workaround ?
| | >
| | > "Steven Cheng[MSFT]" wrote:
| | >
| | >> Hi Ptass,
| | >>
| | >> I Agree with Bruce's explanation. For ASPX page, their page class's
| partial
| | >> class file are particualrly specified through the "codeFile"
attribute
| in
| | >> @Page directive. Also, the source files in App_Code folder will be
| compiled
| | >> into different assemlies with the Page class's assembly, and the
| dynamic
| | >> compilation time and sequence are also different. So manually
provide
| | >> additional partial class file for aspx page is not supported
naturally.
| | >>
| | >> Thanks,
| | >>
| | >> Steven Cheng
| | >> Microsoft Online Support
| |
| |
| | >> | So it can't be done. ?
| | >> |
| | >> | "Bruce Barker" wrote:
| | >> |
| | >> | > the problem is there is no way to tell the asp.net compiler to
| include
| | >> the
| | >> | > third file with an aspx page. each page is built into its own
dll,
| the
| | >> aspx
| | >> | > page has in the page directive then name of the codebehind file
| (see
| | >> | > CodeFile=""), so the two files are compiled into the same
assembly.
| | >> | >
| | >> | > the files in app_code dir are all compiled into one assembly, so
| you
| | >> can use
| | >> | > 3 files here.
| | >> | >
| | >> | >
| | >> | > -- bruce (sqlwork.com)
| |
| | >> | > | | >> | > > Hi
| | >> | > >
| | >> | > > In asp.net 2.0 an aspx files .cs file is a partial class and
all
| | >> works
| | >> | > > fine,
| | >> | > > however,
| | >> | > > I thought I'd be able to create another class file, call it a
| partial
| | >> | > > class
| | >> | > > and have
| | >> | > > that compile and load as a 3rd partial class. This would be
| handy so
| | >> i can
| | >> | > > generate
| | >> | > > standard code into one of the partial classes, while having my
| custom
| | >> code
| | >> | > > untouched
| | >> | > > by the code generator.
| | >> | > >
| | >> | > > However, when i try this, the 3rd .cs file doesn't even seem to
| | >> compile,
| | >> | > > and
| | >> | > > any
| | >> | > > methods contained therein are not visible by the 1st .cs file,
or
| | >> anything
| | >> | > > else
| | >> | > > for that matter.
| | >> | > >
| | >> | > > If I try 3 partial classes that aren't part of an aspx then
| things
| | >> work as
| | >> | > > expected.
| | >> | > >
| | >> | > > So I have 3 files...
| | >> | > >
| | >> | > > Default.aspx
| | >> | > > Default.aspx.cs
| | >> | > > Default_.aspx.cs
| | >> | > >
| | >> | > > Default.aspx and Default.aspx.cs interact as expected.
| | >> | > >
| | >> | > > Default.aspx.cs and Default_aspx.cs both implement partial
class
| | >> Default:
| | >> | > > System.Web.UI.Page
| | >> | > >
| | >> | > > like so...
| | >> | > >
| | >> | > > Default.aspx.cs
| | >> | > >
| | >> | > > public partial class _Default : System.Web.UI.Page
| | >> | > > {
| | >> | > > protected void Page_Load(object sender, EventArgs e)
| | >> | > > {
| | >> | > > TestMethod();
| | >> | > > }
| | >> | > > }
| | >> | > >
| | >> | > > Default_.aspx.cs
| | >> | > >
| | >> | > > public partial class _Default : System.Web.UI.Page
| | >> | > > {
| | >> | > > public bool TestMethod()
| | >> | > > {
| | >> | > > return true;
| | >> | > > }
| | >> | > > }
| | >> | > >
| | >> | > > When i compile the project i get the following error:
| | >> | > > Error 1 The name 'TestMethod' does not exist in the current
| context
| | >> | > > C:\Documents and Settings\petert\My Documents\Visual Studio
| | >> | > > 2005\WebSites\WebSite2\Default.aspx.cs
| | >> | > > 15 9 C:\...\WebSite2\
| | >> | > >
| | >> | > > If i have a non aspx class, with three parts like so...
| | >> | > >
| | >> | > > Class1.cs
| | >> | > > Class1_.cs
| | >> | > > Class1__.cs
| | >> | > >
| | >> | > > public partial class Class1
| | >> | > > {
| | >> | > > public Class1()
| | >> | > > {
| | >> | > > TestMethod1();
| | >> | > > TestMethod2();
| | >> | > > }
| | >> | > > }
| | >> | > >
| | >> | > > public partial class Class1
| | >> | > > {
| | >> | > > public bool TestMethod1()
| | >> | > > {
| | >> | > > return true;
| | >> | > > }
| | >> | > > }
| | >> | > >
| | >> | > > public partial class Class1
| | >> | > > {
| | >> | > > public bool TestMethod2()
| | >> | > > {
| | >> | > > return true;
| | >> | > > }
| | >> | > > }
| | >> | > >
| | >> | > > All compile and work as expected.
| | >> | > >
| | >> | > > I this a limitation with aspx files, or am I missing something.
| | >> | > >
| | >> | > > If there is a specific asp.net 2.0 newsgroup then apologies,
and
| | >> please
| | >> | > > direct me to it.
| | >> | > >
| | >> | > > Also, is there a specific newgroup for asp.net 2.0 / vs2005
| issues ?
| | >> | >
| | >> | >
| | >> | >
| | >> |
| | >>
| | >>
| |
| |
| |
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top