web userControl

柔情痞子 提交于 2019-12-12 03:08:31

问题


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. I have added a web user control and set the reference of App_Code class into the control but it throws an error.

The type or namespace name 'App_Code' does not exist in the namespace (are you missing an assembly reference?)

Any ideas?


回答1:


This point can be confusing.

A "web application project" is not expecting the App_Code folder.

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. 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. Depending upon whether you give the classes in that folder namespaces, you may have to add a reference to that namespace in your UserControl.




回答2:


Did you create the App_Code folder manually?

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.

If the option isn't there is probably because you created a Web Application.
This might help you more: http://vishaljoshi.blogspot.com/2009/07/appcode-folder-doesnt-work-with-web.html



来源:https://stackoverflow.com/questions/8772154/web-usercontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!