Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / January 2004

Tip: Looking for answers? Try searching our database.

Init method firing early

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gozza - 27 Jan 2004 23:41 GMT
Hi,

Looks like I've misunderstood something about controls lifecycles.  I have
an OnInit method override in my control:

protected override void OnInit(EventArgs e)
{
  base.OnInit (e);
  //some stuff
}

The control is then added to an ASPX page and an event handler is assigned
in the Page's OnInit override (as it's usually done by VS.NET, in the
InitilizeComponent method).   The problem is that my event handler does not
get to do its work since the control's OnInit method always gets called
before the Page's OnInit method (i.e. the control's Init event gets
triggered before the Page's) and as a result, the event handler assignment
is made too late.  Can someone please explain to me what's happening?

Any help will be highly appreciated.

Thanks,
Gozza
gozza - 28 Jan 2004 05:28 GMT
Ok, again I'm answering questions to myself, although I am not certain I
like the options.  The only way I can handle the Init event is to create and
add my control in the code-behind file, without making any references to it
in the ASPX page in design mode.  Considering my control's functionality,
this will sort of defeat its purpose.

Now, looks like I will have to find another way to do what I need to: it's
sort of like having a drop-down control with both static and dynamic
elements.  Some of them would be defined in the ASPX file (so they can be
easily modified), and some would be highly dependant on data stored in a
database +  some business rules.  The reason I wanted to handle the Init
event is to be able to create the dynamic elements for the drop-down before
any other processing is done for the drop-down (i.e. the Load Postback Data
handling that happens just AFTER the Init and Load View State).

I guess I'll have to publish my own event that I'll trigger before Load
Postback Data or Load View State or Load.

Btw, I found this earlier post:
---------------------------------------
"The Init event for a control created in Design view is handled in the
OnInit for the page.  If you want to explicitly handle the Init event, you
need to explicitly create the control by doing it dynamically.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
jamesche@online.microsoft.com

This post is provided as-is with no warranties and confers no rights."
---------------------------------------

> Hi,
>
[quoted text clipped - 19 lines]
> Thanks,
> Gozza

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.