将代码隐藏类暴露给app_code .cs文件 [英] Exposing code-behind classes to app_code .cs files

查看:61
本文介绍了将代码隐藏类暴露给app_code .cs文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我决定在此站点上发布,因为它似乎是所有论坛中最友好,最扎实的.我想知道是否有人可以帮助我-我昨天整个时间都在寻找答案,但无济于事!

我几乎用asp.net和c#完成了VS2010网站项目.我从aspx.cs页面看到的app_code/whatever.cs页面中定义的类/方法/字段完全没有问题,但是如果我在aspx.cs页面中定义了一个类,则无法从app_code/what.cs页面.我已经弄乱了名称空间,用法,并确保所有内容都尽可能公开,并证明app_code/whatever.cs可以看到放在app_code另一个.cs页面中的同一个类-仅当将类放入intelisense无法看到的aspx.cs区域. (我得到找不到类型或名称空间名称"xxxxx"(您是否缺少using指令或程序集引用)).aspx.cs页位于解决方案资源管理器中的.aspx文件下方.尝试将what.cs文件从app_code文件夹移至根目录,但这无济于事.

我在互联网上找到的最接近的答案是,我应该创建一个Web应用程序而不是网站,然后才能在两个方向上看到aspx.cs和.cs页面之间的类.

因此,在我开始发布任何代码之前,有人可以告诉我最后一点是否正确吗?道歉,如果真的对每个人都很明显-也许我误解了网站项目中允许数据流动的方式-我对所有这些都是陌生的,所以我的知识可能有根本的不足. ''已设法完成了99%的建设,因此仅需要其余1%的帮助!

但是,如果你们觉得我应该能够将aspx.cs页面类公开给网站项目中的app_code/类,那么我将发布代码并更详细地解释为什么我要这样做.
为了避免被之前已经回答过这个问题"高喊大叫,我可以澄清一下,有很多帖子使人们无法从页面后面的代码中看到app_code中定义的类.....我的问题是反过来说,我真的到处都看过!

非常感谢

Pierreluigi

Hi All,

I decided to post on this site as it seems to be the friendliest and most down to earth of all the forums. I wonder if anyone can help me - I spent all yesterday searching for the answer to no avail!

I have nearly finished a VS2010 Website Project using asp.net and c#. I have no problem at all seeing classes/methods/fields defined in app_code/whatever.cs pages from my aspx.cs pages but if I define a class in the aspx.cs page, I can''t see it from the app_code/whatever.cs page. I''ve messed about with namespaces, usings and made sure everything is as public as possible and have proven that the same class put in another .cs page in app_code can be seen by app_code/whatever.cs - it''s only when put the class into the aspx.cs area that intellisense can''t see it. (I''m getting "The type or namespace name ''xxxxx'' could not be found (are you missing a using directive or assembly reference)). The aspx.cs page sits underneath the .aspx file in solution explorer. I tried moving the whatever.cs file from the app_code folder to root and that didn''t help.

The closest I have found to an answer on the internet is that I should have created a Web Application instead of a Website and then I would be able to see the classes between aspx.cs and .cs pages in both directions.

So, before I start posting any code, could anyone tell me if this last point is true? Apologies if this is really obvious to everyone - maybe I have misunderstood the way data is allowed to flow in a website project - I''m new to all of this so there may be fundamental gaps in my knowledge.....but I''ve managed to build 99% of it so just need help with the remaining 1%!

If you guys feel however that I should be able to expose aspx.cs page classes to the app_code/ classes in a website project then I will post code and explain in more detail why I''m trying to do this.

To avoid being shouted at with "this question has been answered before", can I just clarify that there are loads of posts where people can''t see classes defined in app_code from the code behind page ..... my problem is the other way round, I really have looked everywhere!

Many thanks

Pierreluigi

推荐答案

您将无法访问app_code文件夹中的aspx.cs页面的类,除非将其放在App_Code文件夹下.可能有一种解决方法,可以避免使用BaseClass移动aspx.cs.您可以在这里.

是的,如果您使用"Web应用程序",则可以毫无问题地访问app_code文件夹中的aspx.cs类.
You will not be able to access class of aspx.cs page inside app_code folder unless you put it under App_Code folder. There may be a workaround to avoid moving the aspx.cs by using BaseClass. You can find the details here.

And yes, if you use "web application" you can access aspx.cs class inside app_code folder without any issue.


这篇关于将代码隐藏类暴露给app_code .cs文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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