UserControl Namespace Problem

本文关键字:Problem Namespace UserControl | 更新日期: 2023-09-27 18:07:37

我有一个问题与我的用户控制。我得到一个解析器错误:"无法加载类型'AsMyDotComSite.UserControls.GoogleAnalyticUC'。"我认为这是一个问题与我的名称空间,但我不确定谁能帮助我吗?

My ascx user control file:

<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="MyDotComSite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GoogleAnalyticUC.ascx.cs" Inherits="AsMyDotComSite.UserControls.GoogleAnalyticUC"%>
<!-- Google Analytics -->
<script type="text/javascript">
  //GOOGLE CODE HERE
</script>

我的代码:

namespace AsMyDotComSite.UserControls
{
    public partial class GoogleAnalyticUC : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Visible = ConfigurationManager.AppSettings["IncludeGoogleAnalytics"] == "true" &&
    (SPContext.Current.FormContext.FormMode != SPControlMode.Edit &&
     SPContext.Current.FormContext.FormMode != SPControlMode.New);  
        }
    }
}

UserControl Namespace Problem

这不是打错了吗?您有CodeBehind="GoogleAnalyticUC.ascx.cs",但您说您使用Src="~/_controltemplates/MyDotComSite/GoogleAnalylticUC.ascx"注册它("Analytic"中额外的"l")。除非您手动调整这些文件名,否则这将解释错误—文件是GoogleAnalylticUC.ascxGoogleAnalylticUC.ascx.cs,但您尝试使用不存在的GoogleAnalyticUC.ascx.cs作为后面的代码。