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(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
eg:
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 eg in overrided OnInit
method.
Try this to help solve your problem of some breakpoints working, some not:
This should ensure that your breakpoints are set and hit properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.