WebAppication项目不喜欢单独的代码文件 [英] WebAppication project doesn't like separate codefiles

查看:60
本文介绍了WebAppication项目不喜欢单独的代码文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我的网络应用程序项目(VS.NET 2008):

- 一个webform(webform2.aspx,webform2.aspx) .cs,

webform2.aspx.designer.cs)

- 代码文件Product.cs。


但是我不能在我的页面类中使用''产品'的定义 -

文件(webform2.aspx.cs)


例如:


protected void Page_Load(object sender,EventArgs e)

{

产品p =新产品();

}


编译器不知道产品的定义


而如果我放置产品的定义在与WebForm.cs相同的代码文件中,然后它可以工作。


如何通过将每个类定义保持在其中来实现它的工作原理>
自己的代码文件?

顺便问一下,2005年使用的App_Code发生了什么变化?


谢谢

Chris

Hi,

I have in my web application project (VS.NET 2008) :
- a webform (webform2.aspx, webform2.aspx.cs,
webform2.aspx.designer.cs)
- a code-file Product.cs.

But i can''t use the definition of ''Product'' nowhere in my page-class-
file (webform2.aspx.cs)

For example:

protected void Page_Load(object sender, EventArgs e)
{
Product p = new Product();
}

the compiler doesn''t know the definition of Product

whereas if I place the definition of Product in the same codefile as
the WebForm.cs then it works.

How can i make it work just by keeping each class definition in its
own codefile?
By the way, what happened to the App_Code used in 2005?

thank you
Chris

推荐答案

< ; cm **** @ gmail.com写信息

新闻:39 *************************** ******* @ a1g2000h sb.googlegroups.com ...
<cm****@gmail.comwrote in message
news:39**********************************@a1g2000h sb.googlegroups.com...




我有我的Web应用程序项目(VS.NET 2008):

- 一个webform(webform2.aspx,webform2.aspx.cs,

webform2.aspx.designer.cs)

- 一个代码文件Product.cs。


但我不能在我的页面类中使用''产品'的定义 -

文件(webform2.aspx.cs)


例如:


protected void Page_Load(object sender, EventArgs e)

{

产品p =新产品();

}


编译器不知道产品的定义


而如果我将Product的定义放在与WebOorm.cs相同的代码文件中,那么它的工作原理是。


如何通过将每个类定义保持在其中来实现它的工作

自己的代码文件?

顺便问一下,2005年使用的App_Code发生了什么?
Hi,

I have in my web application project (VS.NET 2008) :
- a webform (webform2.aspx, webform2.aspx.cs,
webform2.aspx.designer.cs)
- a code-file Product.cs.

But i can''t use the definition of ''Product'' nowhere in my page-class-
file (webform2.aspx.cs)

For example:

protected void Page_Load(object sender, EventArgs e)
{
Product p = new Product();
}

the compiler doesn''t know the definition of Product

whereas if I place the definition of Product in the same codefile as
the WebForm.cs then it works.

How can i make it work just by keeping each class definition in its
own codefile?
By the way, what happened to the App_Code used in 2005?



如果App_Code不存在,因为它还没有被创造出来。 App_Code是你的Product.cs所在的
。我建议你使用命名空间作为

好​​的产品这个词很常见。

-

Anthony Jones - MVP ASP / ASP.NET

If App_Code isn''t there its because it hasn''t been created yet. App_Code is
where your Product.cs should be. I would recommend you use a namespace as
well the word ''Product'' is fairly common.
--
Anthony Jones - MVP ASP/ASP.NET


我同意App_Code,如果不在它自己的程序集中。如果不是你喜欢的,请确保你的代码中引用了正确的命名空间

在文件后面/旁边。


-

Gregory A. Beamer

MVP,MCP:+ I,SE,SD,DBA


订阅我的博客
http://gregorybeamer.spaces.live。 com / lists / feed.rss


或只是阅读它:
http://gregorybeamer.spaces.live.com/

*********** *********************************

|创造性思考! |

***************************************** ***

< cm **** @ gmail.com写信息

新闻:39 *************** ******************* @ a1g2000h sb.googlegroups.com ...
I concur with App_Code, if not in its own assembly. If that is not to your
liking, make sure you have the proper namespace referenced in your code
behind/beside file.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
<cm****@gmail.comwrote in message
news:39**********************************@a1g2000h sb.googlegroups.com...




我的Web应用程序项目(VS.NET 2008):

- 一个webform(webform2.aspx,webform2.aspx.cs,

webform2.aspx.designer.cs)

- 代码文件Product.cs。


但是我不能使用定义''产品''无处在我的页面类 -

文件(webform2.aspx.cs)


例如:


protected void Page_Load(object sender,EventArgs e)

{

产品p =新产品();

}


编译器不知道产品的定义


而如果我将Product的定义放在与

WebForm.cs然后它可以工作。


我怎么能它只是将每个类定义保存在其自己的代码文件中吗?

顺便说一句,2005年使用的App_Code发生了什么?

谢谢

Chris
Hi,

I have in my web application project (VS.NET 2008) :
- a webform (webform2.aspx, webform2.aspx.cs,
webform2.aspx.designer.cs)
- a code-file Product.cs.

But i can''t use the definition of ''Product'' nowhere in my page-class-
file (webform2.aspx.cs)

For example:

protected void Page_Load(object sender, EventArgs e)
{
Product p = new Product();
}

the compiler doesn''t know the definition of Product

whereas if I place the definition of Product in the same codefile as
the WebForm.cs then it works.

How can i make it work just by keeping each class definition in its
own codefile?
By the way, what happened to the App_Code used in 2005?

thank you
Chris


8月1日晚上7:39,Cowboy \( Gregory A. Beamer \)"

< NoSpamMgbwo ... @ comcast.netNoSpamMwrote:
On Aug 1, 7:39 pm, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@comcast.netNoSpamMwrote:

我同意App_Code,如果不是在自己的集会中。如果不是你喜欢的,请确保你的代码中引用了正确的命名空间

在文件后面/旁边。


-

Gregory A. Beamer

MVP,MCP:+ I,SE,SD,DBA


订阅我的博客http://gregorybeamer.spaces.live.com/lists/feed.rss


或只是阅读它: http://gregorybeamer.spaces.live.com/

******** ************************************

|创造性思考! |

***************************************** ***< cmr .. @ gmail.com写信息


新闻:39 ******************** ************** @ a1g2000h sb.googlegroups.com ...
I concur with App_Code, if not in its own assembly. If that is not to your
liking, make sure you have the proper namespace referenced in your code
behind/beside file.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my bloghttp://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************<cmr.. .@gmail.comwrote in message

news:39**********************************@a1g2000h sb.googlegroups.com...


Hi,


我的Web应用程序项目(VS.NET 2008):

- 一个webform(webform2.aspx,webform2.aspx.cs,

webform2.aspx.designer.cs)

- 代码文件Product.cs。
I have in my web application project (VS.NET 2008) :
- a webform (webform2.aspx, webform2.aspx.cs,
webform2.aspx.designer.cs)
- a code-file Product.cs.


但我不能在我的页面类中使用''产品'的定义 -

file(webform2.aspx.cs)
But i can''t use the definition of ''Product'' nowhere in my page-class-
file (webform2.aspx.cs)


例如:
For example:


protected void Page_Load(object sender,EventArgs e)

{

Product p = new Product();

}
protected void Page_Load(object sender, EventArgs e)
{
Product p = new Product();
}


编译器不知道Product
的定义
the compiler doesn''t know the definition of Product


而如果我放置在与WebForm.cs相同的代码文件中定义Product然后它的工作原理。
whereas if I place the definition of Product in the same codefile as
the WebForm.cs then it works.


如何通过将每个类定义保存在

自己的代码文件中来使其工作?

顺便问一下,2005年使用的App_Code发生了什么?
How can i make it work just by keeping each class definition in its
own codefile?
By the way, what happened to the App_Code used in 2005?


谢谢

Chris
thank you
Chris



你好,


实际上我以前把代码放在了App_Code中,但即使这样它也没有工作!

只有当我使用它内联它才有效,但不能放入代码 -

后面的文件???


所以,以下工作:

< script runat =" server">

void Button1_Click(object sender,EventArgs e)

{

产品c =新产品();

Label1.Text = c.GetMyMessage(TextBox1.Text);

}

< /脚本>


但不在代码隐藏文件中,为什么会这样?


为什么它不起作用''正常' '方式,我的意思是

中的代码文件与aspx文件相同的目录(它的工作方式与WinForms相同)

或者有办法吗?


谢谢

hello,

actually I previously put the code in App_Code, but even then it
doesn''t work !
Only when I use it inline it works, but not when placed in the code-
behind file ???

So, the following works:
<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
Product c = new Product();
Label1.Text = c.GetMyMessage(TextBox1.Text);
}
</script>

but not in the code-behind file, how come?

why doesn''t it work the ''normal'' way, I mean with the code-files in
the same directory as the aspx-file (it works like that in WinForms)
Or is there a way?

thank you


这篇关于WebAppication项目不喜欢单独的代码文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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