【发布时间】: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