BreakPoint not working in Init, InitComplate, PreLoad events in ASP.NET page with C# in VS2008. But it is working for Page_Load event.
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开发者_JAVA百科(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:
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
e.g.:
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
. Back then, the InitializeComponent
was a place where the IDE serialized construction of the 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 e.g. in overrided OnInit
method.
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
- Open your solution, and re-establish your breakpoints in your events.
This should ensure that your breakpoints are set and hit properly.
精彩评论