C# sharepoint aspx 页面的代码隐藏在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10206756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where's the code-behind for sharepoint aspx pages?
提问by
No doubt I'm missing something very obvious here - but I'm new to sharepoint so please bear with me.
毫无疑问,我在这里遗漏了一些非常明显的东西 - 但我是分享点的新手,所以请耐心等待。
I've successfully added a master page, created a content type and have created an aspx page for my custom content type - but I can't find its cs file!?
我已经成功添加了一个母版页,创建了一个内容类型,并为我的自定义内容类型创建了一个 aspx 页面 - 但我找不到它的 cs 文件!?
Is there another way in which code-behind is implemented in sharepoint solutions? It seems to be similar when creating controls. I'm used to standard asp .net c# web application development were all of the aspx pages come with the code-behind files 'as standard.'
在 sharepoint 解决方案中是否有另一种方式来实现代码隐藏?创建控件时似乎类似。我习惯于标准的 asp .net c# web 应用程序开发,所有 aspx 页面都带有“作为标准”的代码隐藏文件。
Thanks.
谢谢。
采纳答案by Rich Bennema
In SharePoint, you can have a code-behind class, but it needs to be in an assembly, not in an aspx.cs code-behind file.
在 SharePoint 中,您可以有一个代码隐藏类,但它需要在程序集中,而不是在 aspx.cs 代码隐藏文件中。
Using Visual Studio 2010, the Page directive for your aspx page would look something like this:
使用 Visual Studio 2010,您的 aspx 页面的 Page 指令将如下所示:
<%@ Page
Language="C#"
DynamicMasterPageFile="~masterurl/default.master"
Inherits="MyNamspace.MyPage, $SharePoint.Project.AssemblyFullName$"
%>
You can then create a MyNamspace.MyPageclass and do everything you would do in a regular code-behind file.
然后,您可以创建一个MyNamspace.MyPage类并执行您在常规代码隐藏文件中执行的所有操作。
If you take a look at the out of the box aspx pages in the 14 hive\TEMPLATE\LAYOUTS directory, you will see, while some pages have inline code (which is allowed in layouts), almost every page inherits from a class in one of the SharePoint assemblies.
如果您查看 14 hive\TEMPLATE\LAYOUTS 目录中开箱即用的 aspx 页面,您会看到,虽然有些页面具有内联代码(在布局中是允许的),但几乎每个页面都从一个类中继承SharePoint 程序集。
回答by Dante
I advise you to ask this in the SharePoint dedicated site. You can find it here.
我建议您在 SharePoint 专用站点中询问此问题。你可以在这里找到它。
But answering you question, there is no code behind available for you in SharePoint pages, at least in MOSS 2007. Not sure about SharePoint 2010 exactly, but must be the same.
但是回答您的问题,SharePoint 页面中没有可用的代码,至少在 MOSS 2007 中是这样。不确定 SharePoint 2010 是否完全相同,但必须相同。
回答by Paul Leigh
Code-Behind is hidden by design from both 2007 and 2010 versions. See hereto enable it on a per location basis (PageParserPath).
代码隐藏在 2007 和 2010 版本中被设计隐藏。请参阅此处以在每个位置 (PageParserPath) 的基础上启用它。
You'll be better off in the long run in terms of supportability, maintenance and management to stick to convention in SharePoint and use controls rather than code-behind if you can.
从长远来看,在可支持性、维护和管理方面,您会更好地坚持 SharePoint 中的约定并尽可能使用控件而不是代码隐藏。
回答by Jignesh Rajput
you should open your sharepoint .aspxpage in sharepoint designer and add inheritstatements with your .cs class.
您应该sharepoint .aspx在 sharepoint 设计器中打开您的页面并inherit使用 .cs 类添加语句。
something like :
就像是 :
<%@ Page Language="C#" MasterPageFile="~masterurl/default.master" Inherits="Namespace.ClassName,Namespace,Version=1.0.0.0, Culture=neutral, PublicKeyToken=tokenid" %>
one thing is remain as earlier @Paul's Answer you should enable it on a per location basis (PageParserPath).
一件事仍然是早期的@Paul's Answer 你应该在每个位置的基础上启用它(PageParserPath)。

