Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8353109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:09:49+00:00 2026-06-09T09:09:49+00:00

If the AutoEventWireup attribute is set to false , the events need to be

  • 0

If the AutoEventWireup attribute is set to false, the events need to be wired up manually. However, I cannot seem to get the Page_PreInit to fire. I would guess that I might be making the wireup happen too late (once we’re already past Page_PreInit), but I’m not sure where else to put the wireups.

For example…

protected override void OnInit(EventArgs e)
{
    base.OnInit(e)
    PreInit += new EventHandler(Page_PreInit);
    Load += new EventHandler(Page_Load);
}

protected void Page_PreInit(object sender, EventArgs e)
{
    Response.Write("Page_PreInit event fired!<br>");  //this is never reached
}

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Page_Load event fired!<br>");
}

The above code results in “Page_Load event fired!” being displayed, but nothing from Page_PreInit. I tried base.OnInit(e) both before AND after the wireups, and that had no effect.

The graph shown here says that the OnInit method actually comes after the PreInit event. With that in mind, I tried overriding OnPreInit and doing the same thing — no effect.

The MSDN article here explicitly says that in the event of AutoEventWireup set to false, the events can be wired up in an overriden OnInit. The example they use is Page_Load, and of course that works just like it does for me, but they don’t address that this doesn’t seem to work for the Page_PreInit event.

My question is: how can I get the Page_PreInit event wired up in the case of AutoEventWireup set to false?

I understand there are alternatives as listed on the MSDN page, such as using the page’s constructor. I’d like to know specifically how to do like they suggest with OnInit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:09:51+00:00Added an answer on June 9, 2026 at 9:09 am

    The base implementation of the OnPreInit() method is responsible for raising the PreInit event. Since your override calls that implementation before registering your PreInit handler, it will indeed not be called.

    Try calling the base class’ method after registering the handler:

    protected override void OnPreInit(EventArgs e)
    {
        PreInit += new EventHandler(Page_PreInit);
        Load += new EventHandler(Page_Load);
    
        // And only then:
        base.OnPreInit(e);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With AutoEventWireUp set to false, I would normally set a Page_Finalize like this: Include(Self.LoadComplete,
Master page HTML : <%@ Master Language=VB AutoEventWireup=false CodeBehind=PMS.master.vb Inherits=PMS.PMS %> <%@ Register Assembly=AjaxControlToolkit
I want to create my own naming convention for page events rather than AutoEventWireUp
I am new to ASP.NET and am battling to understand why I cannot get
I have following abc.aspx file: <%@ Page Language=vb AutoEventWireup=false Codefile=abc.aspx.vb Inherits=abc %> <html xmlns=http://www.w3.org/1999/xhtml>
Event registered in aspx <asp:Repeater ID=StepRepeater OnItemDataBound=StepRepeater_ItemDataBound1 runat=server> Tried with AutoEventWireUp true & false
I don't understand what the AutoEventWireUp page property is responsible for. I've read through
I have a simple user control with this code: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Pager.ascx.cs"
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Urunler.aspx.cs" Inherits="Urunler" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<%@ Page Language=C# AutoEventWireup=true CodeFile=Default3.aspx.cs Inherits=Default3 %> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.