AppBeCode文件夹中的代码无法访问CodeBehind类. [英] CodeBehind class not accessible to code in App_Code folder.

查看:141
本文介绍了AppBeCode文件夹中的代码无法访问CodeBehind类.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET网站的根文件夹中有一个PlannerShiftView用户控件.在我的App_Code文件夹中,我有一个ShiftViewTemplate类,该类需要实例化PlannerShiftView(用于GridView中的TemplateField).问题是,以下代码无法编译,因为PlannerShiftView类型在我认为是App_Code的虚拟名称空间"中不可用.
请可以有人解释这是怎么回事,以及该怎么做.我知道我可以将ShiftViewTemplate从App_Code中移出,这违背了约定并且没有被移植,但这是一个空洞的胜利.

附录:我认为,由于ShiftViewTemplate确实是UI代码,因此我将其从App_Code中移到了Web根目录中.现在,即使后面的代码位于同一文件夹中,我在PlannerShiftView后面的代码也无法看到ShiftViewTemplate. WTF? :confused:

I have a PlannerShiftView user control in the root folder of my ASP.NET web site. In my App_Code folder, I have a ShiftViewTemplate class that needs to instantiate a PlannerShiftView (for a TemplateField in a GridView). The problem is, the following code doesn''t compile because the PlannerShiftView type is not available in what I deem to be the App_Code ''phantom namespace''.
Please can somebody explain to be what is happening here, as well as what to do. I know I can just move the ShiftViewTemplate out of App_Code, going against convention and without explantion, but that is something of a hollow victory.

ADDENDUM: I thought that since the ShiftViewTemplate was really UI code, I''d move it out of App_Code and into the web root. Now my code behind for PlannerShiftView cannot see the ShiftViewTemplate even though they are in the same folder. WTF? :confused:

推荐答案

您的类只有在将其公开并添加了要调用的特定命名空间后才能访问.
嘿,如果您在Web应用程序中,则可以在App_Code文件夹内之外的任何位置声明类. ;)
Your class is only accessible if you make it public and also have added the particular namespace where you are calling.

Hey, If you are in a web application, you can declare class anywhere other than inside App_Code folder. ;)


哇-引用按钮不见了.

PlannerShiftView是一个控件.您的应用代码不应创建控件实例,而这是您的核心问题.无论您需要从此控件获得什么代码,都需要将其移至应用程序代码区域,以便您创建可在控件之间使用的可重用代码.

BK:是的,不是.我在App_Code中有一个ITemplate,需要实例化控件.这是为了在App_Code中保留尽可能多的代码.不过,请参阅我对该问题的扩展.
Wow - the quote buttons are gone.

The PlannerShiftView is a control. Your App Code should not be creating instances of controls, and that is your core issue. Whatever code you need from this control, needs to be moved into the app code area, for you to create reusable code that can be used between controls.

BK: Yes and no. I have an ITemplate in App_Code that needs to instantiate the control. This is in keeping as much code as possible in App_Code. See my extension to the question though.


这篇关于AppBeCode文件夹中的代码无法访问CodeBehind类.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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