【发布时间】:2010-08-02 22:51:04
【问题描述】:
我在共享点服务器上的文件夹 _layouts/sandbox 中有一个 default.aspx。
代码如下:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.Configuration;
namespace sandbox
{
public partial class _Default : LayoutsAppPage
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
LabelTitle.Text = web.Title;
if (Page.IsPostBack == false)
{
//Label1.Text = "Fahrenheit to Celsius:";
}
}
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
try
{
this.MasterPageFile = SPContext.Current.Web.MasterUrl;
}
catch
{
}
}
}
}
它应该继承 LayoutsAppPage 类,以便我可以使用它在“沙盒”应用程序的所有页面中执行 OnPreInit 函数。这是同一目录下 LayoutsAppPage.aspx.cs 的代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.Configuration;
namespace sandbox
{
public class LayoutsAppPage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
try
{
this.MasterPageFile = SPContext.Current.Web.MasterUrl;
}
catch
{
}
}
}
}
运行页面时出现以下错误
c:\Program Files\Common 文件\Microsoft 共享\Web 服务器 Extensions\12\TEMPLATE\LAYOUTS\sandbox\Default.aspx.cs(20): 错误 CS0246:类型或命名空间 名称“LayoutsAppPage”不能是 找到(您是否缺少使用 指令还是程序集引用?)
在 System.Web.Compilation.AssemblyBuilder.Compile()
我确实注意到,在“public partial class _Default: LayoutsAppPage”行中,LayoutsAppPage 不会像基类那样变成浅蓝色。如果该行是“公共部分类 _Default:System.Web.UI.Page”,则页面加载正常。也许我错误地声明了基本页?
编辑:按要求 -
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="sandbox._Default" MasterPageFile="~/_layouts/application.master" %>
<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages,Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormSection" Src="/_controltemplates/InputFormSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormControl" Src="/_controltemplates/InputFormControl.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ButtonSection" Src="/_controltemplates/ButtonSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" Src="/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" Src="/_controltemplates/ToolBarButton.ascx" %>
【问题讨论】:
-
你能把所有的 指令都贴在你的标记页面的顶部吗?
-
我已将它们全部添加到原始帖子的末尾,感谢您查看 kbrimington。
-
我可能会抓住稻草,所以我将仅作为评论发布。我总是在 @Page 指令的 Inherits 属性中使用类的程序集限定名称。此外,请仔细检查您的所有 .cs 文件都设置为在项目中编译。此外,请确保您使用的是 Web 应用程序项目而不是网站。祝你好运!
-
抱歉,您能解释一下您对 assembley 限定名称的含义吗?我对 asp.net/c# 还很陌生,我在尝试解决很多问题。
标签: c# asp.net sharepoint