|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
load event doesn't fire unless init event is presentHi,
I have a custom control that is just a .cs file with no ascx file (in fact it is a templated control so the rendered HTML is in the aspx page that embeds it). It inherits from System.Web.UI.UserControl. It uses the standard structure generated by visual studio with OnInit calling InitializeComponent which initialises the event handlers. I have found that if I include only a Load event handler it never gets called. However, if I include both Init and Load event handlers, they both get called as expected. Is this a bug in the framework or have I implemented the control wrongly? TIA Andy Andy,
With the exception of the Init event (which is implicitly called when the control is first created), all Event Handlers must be "wired up" somewhere in your code. This is typically done in the OnInit Event Handler(which is called when the Init event is fired). As it would turn out, the only place that the Load Event Handler can be wired up is in the OnInit call, since there are no events that get fired between Init and Load (see the MSDN Article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp) The "wiring" up of the Load eventhandler would look something like this: this.Init+=new EventHandler(control_Init) Best practices for development has the events getting wired up at the earliest possible time in the page/control's lifecycle. For Aspx pages and User Controls this is typically in the OnInit overload; for server and composite controls there may be some exceptions... Hope it helps, for more information on Events and Delegates you might try the following MSDN resource: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconeventsinwebformscontrols.asp -- Show quoteHide quoteCheers, Jonathan "Andy Fish" wrote: > Hi, > > I have a custom control that is just a .cs file with no ascx file (in fact > it is a templated control so the rendered HTML is in the aspx page that > embeds it). It inherits from System.Web.UI.UserControl. It uses the standard > structure generated by visual studio with OnInit calling InitializeComponent > which initialises the event handlers. > > I have found that if I include only a Load event handler it never gets > called. However, if I include both Init and Load event handlers, they both > get called as expected. > > Is this a bug in the framework or have I implemented the control wrongly? > > TIA > > Andy > > > Sorry, forgot to answer your question clearly.
If the only place that the Load event can be wired up is the Init then if you take out that Event, there is no way your Load event is getting wired up. -- Show quoteHide quoteCheers, Jonathan "Jonathan Mast" wrote: > Andy, > > With the exception of the Init event (which is implicitly called when the > control is first created), all Event Handlers must be "wired up" somewhere in > your code. This is typically done in the OnInit Event Handler(which is > called when the Init event is fired). > > As it would turn out, the only place that the Load Event Handler can be > wired up is in the OnInit call, since there are no events that get fired > between Init and Load (see the MSDN Article: > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp) > The "wiring" up of the Load eventhandler would look something like this: > > this.Init+=new EventHandler(control_Init) > > Best practices for development has the events getting wired up at the > earliest possible time in the page/control's lifecycle. For Aspx pages and > User Controls this is typically in the OnInit overload; for server and > composite controls there may be some exceptions... > > Hope it helps, for more information on Events and Delegates you might try > the following MSDN resource: > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconeventsinwebformscontrols.asp > -- > Cheers, > > Jonathan > > > > "Andy Fish" wrote: > > > Hi, > > > > I have a custom control that is just a .cs file with no ascx file (in fact > > it is a templated control so the rendered HTML is in the aspx page that > > embeds it). It inherits from System.Web.UI.UserControl. It uses the standard > > structure generated by visual studio with OnInit calling InitializeComponent > > which initialises the event handlers. > > > > I have found that if I include only a Load event handler it never gets > > called. However, if I include both Init and Load event handlers, they both > > get called as expected. > > > > Is this a bug in the framework or have I implemented the control wrongly? > > > > TIA > > > > Andy > > > > > >
Validation controls validate before form submits
binding - DropDownList flaw/bug? Who is the true Asp.Net MVP here? asp 2.0 wizard control (how to set focus on button) Trying hard to implement globalisation. Strange error message(urgent help needeed) Can't get the Microsoft Web Library Finding the leftmost pixel in a piece of text when using GDI+ How to view properties of control inside table Client Side Calculation involving controls in datagrid template co Dragging and Dropping HTML instead of text |
|||||||||||||||||||||||