C# 为什么UserControl Page_PreInit事件不触发?

C# 为什么UserControl Page_PreInit事件不触发?,c#,asp.net,C#,Asp.net,在用户控件页面中,未触发preinit事件。 代码如下所示: protected void Page_PreInit(object Sender, EventArgs e) { if (!Page.User.Identity.IsAuthenticated && !Page.User.IsInRole("Admin")) { Response.Redirect("abcd/Index.aspx?Auth=Fail"); } e

在用户控件页面中,未触发preinit事件。 代码如下所示:

protected void Page_PreInit(object Sender, EventArgs e)
{   
    if (!Page.User.Identity.IsAuthenticated && !Page.User.IsInRole("Admin"))
    {
        Response.Redirect("abcd/Index.aspx?Auth=Fail");
    }
    else
    {
        FormsIdentity id = (FormsIdentity)Page.User.Identity;
        FormsAuthenticationTicket ticket = id.Ticket;
        String[] userDatas = ticket.UserData.Split('|');
        ViewState["Role"] = userDatas[0];
        ViewState["Language"] = userDatas[2];
        this.Page.Theme = userDatas[1];
    }
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
    Response.Cache.SetNoStore();
}
有什么想法吗?

用户控件实际上是从类派生的,没有任何可用的PreInit事件

继承层次

PreInit事件可用于Page类。

用户控件实际上是从类派生的,没有任何PreInit事件可用

继承层次


PreInit事件可用于Page类。

也将设计页面放在一边。用户控件上的AutoEventWireup属性是如何设置的?在你的页面上?不知道为什么这个问题被否决了。对于用户控件来说,PreInit是否没有被激活一点也不明显,特别是如果你把大部分时间都花在查看页面上的话。把你的设计页面也放在一边。你的用户控件上的AutoEventWireup属性是如何设置的?在你的页面上?不知道为什么这个问题被否决了。PreInit是否不是为用户控件而启动的一点也不明显,特别是如果您将大部分时间花在查看页面上。
System.Object
  System.Web.UI.Control
    System.Web.UI.TemplateControl
      System.Web.UI.UserControl