asp.net 2.0中的2个或更多部分类和aspx文件 [英] 2 or more partial classes and an aspx file in asp.net 2.0

查看:76
本文介绍了asp.net 2.0中的2个或更多部分类和aspx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在asp.net 2.0中,一个aspx文件.cs文件是一个部分类,一切正常,

然而,

我以为我能够创建另一个类文件,将其称为部分类

并且具有

编译并加载为第3部分类。这将是方便的所以我可以

生成

标准代码到其中一个部分类中,同时拥有我的自定义代码

未触及
代码生成器。


然而,当我试试这个时,第3个.cs文件似乎甚至无法编译,并且

any

方法包含在第一个.cs文件中,或者其他任何内容






如果我尝试3个部分类,那些是aspx的一部分,那么事情就像

预期的那样。


所以我有3个文件...


Default.aspx

Default.aspx.cs

Default_.aspx.cs


Default.aspx和Default.aspx.cs按预期进行交互。


Default.aspx.cs和Default_aspx.cs都实现了分部类默认值:

System.Web.UI.Page


就像这样...


Default.aspx.cs


public partial class _Default:System.Web.UI.Pa ge

{

protected void Page_Load(object sender,EventArgs e)

{

TestMethod(); < br $>
}

}


Default_.aspx.cs


public partial class _Default :System.Web.UI.Page

{

public bool TestMethod()

{

return true;

}

}


当我编译项目时,我收到以下错误:

错误1当前上下文中不存在名称TestMethod

C:\Documents and Settings \petert\My Documents\Visual Studio

2005 \ WebSites\WebSite2 \Default.aspx.cs

15 9 C:\ ... \\\ netSite2 \


如果我有非aspx类,有三个部分,如此...


Class1.cs

Class1_.cs

Class1 __。cs


公共部分班级Class1

{

public Class1()

{

TestMethod1();

TestMethod2();

}

}


公共部分类Class1

{

public bool TestMethod1()

{

返回true;

}

}


公共部分班级Class1

{

公共布尔TestMethod2()

{

返回true;

}

}


全部按预期编译和工作。


我这是aspx文件的限制,或者我错过了什么。


如果有特定的asp.net 2.0新闻组,那么道歉,并请

指示我。


此外,是否有针对asp.net 2.0 / vs2005问题的特定新组?

解决方案

re:

所以我有3个文件......

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


将Default_.aspx.cs删除到App_Code目录中。



Juan T. Llibre,A SP.NET MVP

ASP.NET常见问题解答: http:// asp.net.do/faq/

ASPNETFAQ.COM: http://www.aspnetfaq.com/

Foros de ASP.NET en Espa?ol: http://asp.net.do/foros/

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

" ptass" < PT *** @ newsgroup.nospam>在消息中写道

新闻:B5 ********************************** @ microsof t.com ...嗨

在asp.net 2.0中,一个aspx文件.cs文件是一个部分类,一切正常,但是,
我以为我'' d能够创建另一个类文件,将其称为部分类
并编译并加载为第3部分类。这样会很方便,所以我可以将标准代码生成一个部分类,同时让我的自定义代码不受代码生成器的影响。
方法都不会被第一个.cs文件或其他任何内容看到/>
就此而言。

如果我尝试3个不属于aspx的部分类,那么事情就像
预期的那样。

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

Default.aspx和Default.aspx.cs按预期交互。

Default.aspx.cs和Default_aspx.cs都实现了部分类默认值:
System.Web.UI.Page

Default.aspx.cs
公共部分类_Default:System.Web.UI.Page
{
受保护void Page_Load(object sender,EventArgs e)
{
测试方法();
}

Default_.aspx.cs
公共部分类_Default:System.Web.UI.Page
{
公共bool TestMethod()
{
返回true;
}

当我编译项目时,我得到以下内容错误:
错误1当前上下文中不存在名称TestMethod
C:\ Document and Settings \petert \ My Documents \ Visual Studio 2005 \\ \ nWebSites\WebSite2 \Default.aspx.cs
15 9 C:\ ... \ WebSite2 \

如果我有一个非aspx类,有三个部分像所以...

Class1.cs
Class1_.cs
Class1 __。cs

公共部分类Class1
{
public Class1()
{
TestMethod1();
TestMethod2();
}
}
公共部分类Class1
{
public bool TestMethod1()
{
返回true;
}
}
<公共部分班级Class1
公共布尔TestMethod2()
{
返回true;
}
}
所有编译和按预期工作。

我这是aspx文件的限制,或者我错过了什么。

如果有一个特定的asp.net 2.0新闻组,那么道歉,请
指引我。

此外,是否有针对asp.net 2.0 / vs2005问题的特定新组?



问题是没有办法告诉asp.net编译器在aspx页面中包含

第三个文件。每个页面都内置在自己的dll中,aspx

页面在页面指令中有代码隐藏文件的名称(参见

CodeFile =""),所以这两个文件被编译到同一个程序集中。


app_code目录中的文件都编译成一个程序集,所以你可以在这里使用

3文件。

- 布鲁斯(sqlwork.com)


" ptass" < PT *** @ newsgroup.nospam>在消息中写道

新闻:B5 ********************************** @ microsof t.com ...



在asp.net 2.0中,aspx文件.cs文件是一个部分类,所有工作都很好,但是,
我以为我能够创建另一个类文件,称之为部分类
并且编译并加载为第3个分类。这样会很方便,所以我可以将标准代码生成一个部分类,同时让我的自定义代码不受代码生成器的影响。

其中包含的任何方法都不会被第一个.cs文件看到,或其他什么




如果我尝试3个不属于aspx的部分类,那么事情就像
预期的那样。 />
所以我有3个文件......

Default.aspx
Default.aspx.cs
Default_.aspx.cs
Default.aspx和Default.aspx.cs按预期进行交互。

Default.aspx.cs和Default_aspx.cs都实现了部分类默认值:
System.Web.UI.Page
Default.aspx.cs
公共部分类_Default:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)

TestMethod();
}


Default_.aspx.cs
公共部分类_Default:System.Web.UI.Page
{
公共bool TestMethod()
{
返回true;
}

当我编译项目时,我得到以下内容错误:
错误1当前上下文中不存在名称TestMethod
C:\ Document and Settings \petert \ My Documents \ Visual Studio 2005 \\ \ nWebSites\WebSite2 \Default.aspx.cs
15 9 C:\ ... \ WebSite2 \

如果我有一个非aspx类,有三个部分像所以...

Class1.cs
Class1_.cs
Class1 __。cs

公共部分类Class1
{
public Class1()
{
TestMethod1();
TestMethod2();
}
}
公共部分类Class1
{
public bool TestMethod1()
{
返回true;
}
}

公共部分班级Class1
公共布尔TestMethod2()
{
返回true;
}
}
所有编译和按预期工作。

我这是aspx文件的限制,或者我错过了什么。

如果有特定的asp.net 2.0新闻组然后道歉,并请
指示我。

此外,是否有针对asp.net 2.0 / vs2005问题的特定新组?



这并没有解决问题。

我仍​​然得到测试方法在当前

上下文中不存在的错误。


" Juan T. Llibre"写道:

re:

所以我有3个文件......

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



将Default_.aspx.cs放到App_Code目录中。


Juan T. Llibre ,ASP.NET MVP
ASP.NET常见问题解答: http://asp.net .do / faq /
ASPNETFAQ.COM: http:// www。 aspnetfaq.com/
Foros de ASP.NET en Espa?±ol: http://asp.net.do/foros/
============================ ==========
" ptass" < PT *** @ newsgroup.nospam>在消息中写道
新闻:B5 ********************************** @ microsof t.com。 ..



在asp.net 2.0中,一个aspx文件.cs文件是一个部分类,一切正常,但是,
我以为我能够创建另一个类文件,称之为部分类
并且编译并加载为第3部分类。这样会很方便,所以我可以将标准代码生成一个部分类,同时让我的自定义代码不受代码生成器的影响。
方法都不会被第一个.cs文件或其他任何内容看到/>
就此而言。

如果我尝试3个不属于aspx的部分类,那么事情就像
预期的那样。

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

Default.aspx和Default.aspx.cs按预期交互。

Default.aspx.cs和Default_aspx.cs都实现了部分类默认值:
System.Web.UI.Page

Default.aspx.cs
公共部分类_Default:System.Web.UI.Page
{
受保护void Page_Load(object sender,EventArgs e)
{
测试方法();
}

Default_.aspx.cs
公共部分类_Default:System.Web.UI.Page
{
公共bool TestMethod()
{
返回true;
}

当我编译项目时,我得到以下内容错误:
错误1当前上下文中不存在名称TestMethod
C:\ Document and Settings \petert \ My Documents \ Visual Studio 2005 \\ \ nWebSites\WebSite2 \Default.aspx.cs
15 9 C:\ ... \ WebSite2 \

如果我有一个非aspx类,有三个部分像所以...

Class1.cs
Class1_.cs
Class1 __。cs

公共部分类Class1
{
public Class1()
{
TestMethod1();
TestMethod2();
}
}
公共部分类Class1
{
public bool TestMethod1()
{
返回true;
}
}
<公共部分班级Class1
公共布尔TestMethod2()
{
返回true;
}
}
所有编译和按预期工作。

我这是aspx文件的限制,或者我错过了什么。

如果有一个特定的asp.net 2.0新闻组,那么道歉,请
指引我。

此外,是否有针对asp.net 2.0 / vs2005问题的特定新组?




Hi

In asp.net 2.0 an aspx files .cs file is a partial class and all works fine,
however,
I thought Ia??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 arena??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 ?

解决方案

re:

So I have 3 files...

Default.aspx
Default.aspx.cs
Default_.aspx.cs
Drop Default_.aspx.cs into the App_Code directory.


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/
======================================
"ptass" <pt***@newsgroup.nospam> wrote in message
news:B5**********************************@microsof t.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 ?



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)


"ptass" <pt***@newsgroup.nospam> wrote in message
news:B5**********************************@microsof t.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 ?



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

"Juan T. Llibre" wrote:

re:

So I have 3 files...

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



Drop Default_.aspx.cs into the App_Code directory.


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/
======================================
"ptass" <pt***@newsgroup.nospam> wrote in message
news:B5**********************************@microsof t.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 ?




这篇关于asp.net 2.0中的2个或更多部分类和aspx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆