簡體   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在VS2008中使用C#在ASP.NET頁的Init,InitComplate,PreLoad事件中不起作用。 但它適用於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)
        {
         ..........
        }
    }

編輯:將您的處理程序添加到OnInit而不是InitializeComponent方法中:

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

但是實際上您根本不需要這些初始化程序,因為所有這些處理程序都可以通過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)
    {
     .........
    }
}

編輯二:據我所知, InitializeComponent是用於VS 2003, .NET v1.1 那時, InitializeComponent是IDE序列化WebForm結構的地方。 現在,此方法永遠不會從您的代碼中調用,因此沒有您期望(應該添加)的事件處理程序。 現在,有2個選項可以添加處理程序:對於一般的Page事件,例如在重寫的OnInit方法中,具有AutoEventWireUp=true

嘗試使用此方法可幫助您解決某些斷點起作用的問題,有些斷點不能起作用:

  • 在“調試”菜單中,選擇“刪除所有斷點”
  • 保存您的解決方案並關閉Visual Studio
  • 打開解決方案,然后在事件中重新建立斷點。

這應該確保您的斷點設置正確並命中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM