简体   繁体   English

web userControl

[英]web userControl

I have create a new empty web application in c# Asp.net 4.0 and then added App_Code folder then added 3 classes into that folder. 我在c#Asp.net 4.0中创建了一个新的空Web应用程序,然后添加了App_Code文件夹,然后在该文件夹中添加了3个类。 I have added a web user control and set the reference of App_Code class into the control but it throws an error. 我添加了一个Web用户控件并将App_Code类的引用设置为控件但它会引发错误。

The type or namespace name 'App_Code' does not exist in the namespace (are you missing an assembly reference?) 命名空间中不存在类型或命名空间名称“App_Code”(您是否缺少程序集引用?)

预习

Any ideas? 有任何想法吗?

This point can be confusing. 这一点可能令人困惑。

A " web application project " is not expecting the App_Code folder. Web应用程序项目 ”不期望App_Code文件夹。

A " website project " would expect that folder and know how to use it. 网站项目 ”会期望该文件夹并知道如何使用它。

Whether you realize it or not (and depending upon which version of Visual Studio you use), you will get a WAP or a WSP when you first create your web solution. 无论您是否意识到(并且取决于您使用的Visual Studio版本),您在首次创建Web解决方案时都将获得WAP或WSP。 They are different. 他们是不同的。 It takes some effort to convert from one to the other. 从一个转换到另一个需要一些努力。

Here are a few articles explaining the differences. 以下一些解释差异的文章

To solve your immediate problem, then, you can just move the 3 class files out of the App_Code folder into the root folder, or better, create a new folder to contain those classes and move them into it. 为了解决您当前的问题,您可以将3个类文件从App_Code文件夹中移出到根文件夹中,或者更好的是,创建一个新文件夹以包含这些类并将其移入其中。 Depending upon whether you give the classes in that folder namespaces, you may have to add a reference to that namespace in your UserControl . 根据您是否在该文件夹命名空间中提供类,您可能必须在UserControl添加对该命名空间的引用。

Did you create the App_Code folder manually? 您是否手动创建了App_Code文件夹?

I was the impression the folder was created automaticaly when creating the project. 我是在创建项目时自动创建文件夹的印象。

If not, when you add something to the project you select Add ASP folder, and it would have App_Code option along others there. 如果没有,当你向项目中添加一些内容时,你选择Add ASP文件夹,它就会有其他的App_Code选项。

If the option isn't there is probably because you created a Web Application . 如果选项不存在,可能是因为您创建了Web应用程序
This might help you more: http://vishaljoshi.blogspot.com/2009/07/appcode-folder-doesnt-work-with-web.html 这可能对您有所帮助: http//vishaljoshi.blogspot.com/2009/07/appcode-folder-doesnt-work-with-web.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM