【问题标题】:"control name" must be convertable to System.Web.UI.Page“控件名称”必须可转换为 System.Web.UI.Page
【发布时间】:2011-08-14 06:44:47
【问题描述】:

我刚刚将一个 VB.NET 项目转换为 C#。但是现在即使这个继承的命名空间是正确的,我所有的 .aspx 页面都一直说“[控件名称]必须可以转换为 System.Web.UI.Page”

因此,在本例中,当我将鼠标悬停在 Activate 上时,我得到“Activate must be convertable to System.Web.UI.Page”

<%@ Page Language="C#" Inherits="Forum.UI.Activate"  Codebehind="Activate.aspx.cs" %>


<asp:Content ID="ctlContent" ContentPlaceHolderID="ctlContentPlaceHolder" runat="Server">
</asp:Content>

这是激活控件:

namespace Forum.UI
{
    /// <summary>
    /// Code behind for Skins/SkinName/Activate.ascx.
    /// </summary>
    /// <remarks></remarks>
    public class Activate : SkinControl
    {
        #region Private Variables

        private string Key;
        private Int32 UserID;

        #endregion

        #region Constructor

        public Activate()
        {
            base.SkinFileName = "Activate.ascx";
        }

        #endregion

        #region Initialize

        protected override void Initialize(Control ctlSkin)
        {
            // track whos on information
            base.TrackSession(EnumTask.ActivatingAccount);

            // get querystring values
            Key = base.CurrentContext.CurrentRequest.Key;
            UserID = base.CurrentContext.CurrentRequest.UserID;

            if (System.Web.HttpContext.Current.Request.IsAuthenticated)
            {
                if (UserID != base.CurrentContext.CurrentUser.UserID)
                {
                    // logout currently logged in user
                    Authentication.Logout();
                    // redirect to this page to refresh controls
                    Common.Globals.Paths.Redirect(Paths.Activate(UserID, Key), false, false);
                }
            }


            bool ActivationSuccess = User.ActivateAccount(UserID, Key,
                                                          base.CurrentContext.CurrentSettings.SharedSettings.
                                                              DefaultUserRoleID);


            if (ActivationSuccess)
            {

                Business.User.UpdatePermissionSet(UserID, 0);


                UserRoles.DeleteUserRole(UserID,
                                         base.CurrentContext.CurrentSettings.SharedSettings.
                                             DefaultAwaitingApprovalRoleID);

                UserRoles.AddUserRole(UserID, base.CurrentContext.CurrentSettings.SharedSettings.DefaultUserRoleID);


                Sessions.Add(EnumSessionObjects.ConfirmationHeader.ToString(), "Confirmation_HeaderActivationComplete");
                Sessions.Add(EnumSessionObjects.ConfirmationMesssage.ToString(), "Confirmation_TextActivationComplete");
            }
            else
            {

                Sessions.Add(EnumSessionObjects.ConfirmationHeader.ToString(), "Confirmation_HeaderActivationError");
                Sessions.Add(EnumSessionObjects.ConfirmationMesssage.ToString(), "Confirmation_TextActivationError");
            }

            Business.User.ClearCache(base.CurrentContext.CurrentUser);


            Common.Globals.Paths.Redirect(Paths.ConfirmationMessage(Sessions.SessionID()), false, false);
        }

        #endregion
    }
}

SkinControl.cs 继承 BaseSkinControl.cs,然后 BaseSkinControl.cs 继承自定义 UserControl.cs 类,最后 UserControl.cs 继承 System.Web.UI.UserControl。

同样的代码在 VB.NET 中工作得很好,所以我不确定它为什么会抱怨。我花了无数个小时试图排除故障,所以我把它扔在这里,希望有人猜测为什么这无法解决。

我不知道这是否足够的信息,但如果没有,请告诉我。

【问题讨论】:

  • 我想问题不在于用户控件层次结构,而在于您在页面中使用用户控件的位置(问题在您的页面中)。
  • 是的,但这在 VB.NET 中也能正常工作,完全相同的解决方案。
  • 如果您可以发布一些页面代码而不是用户控制代码,这可能有助于我们找出问题。
  • 你找到问题了吗?我也有类似的问题。

标签: asp.net


【解决方案1】:

错误消息是正确的,因为您发布的代码适用于 UserControl,而不适用于 Page。他们不是一回事。您甚至可以在该 Activate 类的 cmets 中看到,它是 ASCX 文件的代码隐藏,而不是 ASPX 页面:

/// Skins/SkinName/Activate.ascx 的代码。

从您发布的继承层次结构中也可以清楚地看出这是针对 UserControl。

检查您的 VB 代码并确保它实际上是一个 ASPX 页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-24
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    相关资源
    最近更新 更多