简体   繁体   English

BreakPoint无法在VS2008中使用C#在ASP.NET页的Init,InitComplete,PreLoad事件中运行

[英]BreakPoint not working in Init, InitComplete, PreLoad events in ASP.NET page with C# in VS2008

BreakPoint not working in Init, InitComplate, PreLoad events in ASP.NET page with C# in VS2008. BreakPoint在VS2008中使用C#在ASP.NET页的Init,InitComplate,PreLoad事件中不起作用。 But it is working for Page_Load event. 但它适用于Page_Load事件。

public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void InitializeComponent()
        {
            this.PreLoad += new System.EventHandler(this._Default_PreLoad);
            this.InitComplete += new System.EventHandler(this._Default_InitComplete);
            this.Init += new System.EventHandler(this._Default_Init);
            this.PreRender += new System.EventHandler(this._Default_PreRender);
            this.PreInit += new System.EventHandler(this._Default_PreInit);
            this.SaveStateComplete += new System.EventHandler(this._Default_SaveStateComplete);

        }

        protected void _Default_InitComplete(object sender, EventArgs e)
        {
              ........
        }

        protected void _Default_Init(object sender, EventArgs e)
        {
         .........
        }

        protected void _Default_PreLoad(object sender, EventArgs e)
        {
         ..........
        }
    }

EDIT: move your handlers adding into the OnInit instead of InitializeComponent method: 编辑:将您的处理程序添加到OnInit而不是InitializeComponent方法中:

  override protected void OnInit(EventArgs e)
  {
     // move your initializers here
  } 

But actually you don't need these initializers at all because of all these handlers could be hooked automatically with AutoEventWireUp=true eg: 但是实际上您根本不需要这些初始化程序,因为所有这些处理程序都可以通过AutoEventWireUp=true自动挂接,例如:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Page_PreLoad(object sender, EventArgs e)
    {
     .........
    }

    protected void Page_InitComplete(object sender, EventArgs e)
    {
          ........
    }

    protected void Page_Init(object sender, EventArgs e)
    {
     .........
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
     .........
    }

    protected void Page_SaveStateComplete(object sender, EventArgs e)
    {
     .........
    }
}

EDIT II: As far as I remember, InitializeComponent is for VS 2003, .NET v1.1 . 编辑二:据我所知, InitializeComponent是用于VS 2003, .NET v1.1 Back then, the InitializeComponent was a place where the IDE serialized construction of the WebForm. 那时, InitializeComponent是IDE序列化WebForm结构的地方。 Now this method get never called from your code, so there are no event handlers you expected (and supposed to be added). 现在,此方法永远不会从您的代码中调用,因此没有您期望(应该添加)的事件处理程序。 Now there are 2 options to add hanlers: with AutoEventWireUp=true for general Page events and eg in overrided OnInit method. 现在,有2个选项可以添加处理程序:对于一般的Page事件,例如在重写的OnInit方法中,具有AutoEventWireUp=true

Try this to help solve your problem of some breakpoints working, some not: 尝试使用此方法可帮助您解决某些断点起作用的问题,有些断点不能起作用:

  • In the Debug menu, select "Delete All Breakpoints" 在“调试”菜单中,选择“删除所有断点”
  • Save your solution and close Visual Studio 保存您的解决方案并关闭Visual Studio
  • Open your solution, and re-establish your breakpoints in your events. 打开解决方案,然后在事件中重新建立断点。

This should ensure that your breakpoints are set and hit properly. 这应该确保您的断点设置正确并命中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM