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 / Web Controls / June 2004

Tip: Looking for answers? Try searching our database.

Can web control events fire FIRST?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
William Parker - 26 Jun 2004 21:00 GMT
I have a user web control I wrote which is registered in my webforms.  By
default the web form's Page_Load is firing first, and then the web user
control's Page_Load is firing.

I want to set it up so that the web control's event fires first, before the
web form's (or any other controls page_load fires).  Is this possible?

Consider this hidden code section (hidden by VS.NET by default) in the web
control's user form:

 private void InitializeComponent()
 {
  this.Load += new System.EventHandler(this.Page_Load);
 }

Would it be possible for me to write code that enumerated all the registered
events and then rewrote them back in an order to ensure its Page_Load was
called first?  Or perhaps there is an easier way for me to accomplish this?

Also, as a side note, is the Page_Load event the first event to fire on a
page?  For example I'm looking to do something on the page that happens at
the very beginning that the page is called.  Not at the httpmodule level,
but ideally there would be no processing prior to the point where I could do
some things - if Page_Load is not the event is there another one I can
capture?

Thanks.
Robert Koritnik - 28 Jun 2004 10:15 GMT
No. The first event is OnInit.
But using it depends on what you intend to do. Some
properties/values/references may not yet be set by that time.

Signature

RobertK
{ Clever? No just smart. }

> I have a user web control I wrote which is registered in my webforms.  By
> default the web form's Page_Load is firing first, and then the web user
[quoted text clipped - 23 lines]
>
> Thanks.
William Parker - 28 Jun 2004 23:57 GMT
OnInit would be even better.  But I really need a way to organize the events
so that the OnInit event is fired in my custom control first.  Is this
possible?

> No. The first event is OnInit.
> But using it depends on what you intend to do. Some
[quoted text clipped - 3 lines]
> RobertK
> { Clever? No just smart. }
Robert Koritnik - 29 Jun 2004 08:32 GMT
Why do you need to execute control's events first... could you enlighten us
a bit? Maybe we would offer a different approach.

Signature

RobertK
{ Clever? No just smart. }

> OnInit would be even better.  But I really need a way to organize the events
> so that the OnInit event is fired in my custom control first.  Is this
[quoted text clipped - 7 lines]
> > RobertK
> > { Clever? No just smart. }
William Parker - 30 Jun 2004 01:38 GMT
I am producing a user control that partner sites will include in all their
ASP.NET pages.  This control is responsible for logging important
information about the request to a database.  It is critical that my control
log this data before any of their controls or pages begin to execute for
reasons too complicated to go into.  So I want to make certain that my
OnInit event fires before any others on their page.

Technically this particular user control does not produce any HTML output.
This user control  actually is a "smart wrapper" of sorts for my class
library.  So instead of giving the third party developers several lines of
code to set properties and call methods of in my class library, I'm wrapping
everything that needs to be done into a web control.  That way they just
need to register and include the user control in their page, and the control
will take care of the more complicated use of the class library for them.
Is this the right approach to encapsulating complicated calls to a class
library and make it easy for more novice programmers to call?

In any event, if there was a clever way for me to ensure my OnInit event
would fire first that would be great.

Thank you.

> Why do you need to execute control's events first... could you enlighten us
> a bit? Maybe we would offer a different approach.
[quoted text clipped - 15 lines]
> > > RobertK
> > > { Clever? No just smart. }
Robert Koritnik - 30 Jun 2004 09:14 GMT
Normally things are executed this way:
- constructor: page first then all controls
- OnInit: controls first, then the page
- OnLoad: page first, then controls
- other events...

Decide for yourself. If you have the data by the time constructor is called
use that. That's the very first time your control executes any code.

then there is LoadViewState and so many other methods. Check MSDN what else
you could use. Check creating server controls articles.

I suggest you really check some very deep articles, because making good
server controls shouldn't be held as an easy task eventhough it looks like
that.

Check this article on MSDN: "Understanding ASP.NET ViewState" it will
explain many things about this and maybe you'll get another idea (like
inheriting a Page class instead of including your own server control on
every page) I think since your control doesn't have a visualization part I
would create my own class inherited from Page that would do this. Any child
private events are FIRST called on the base class, SECOND on the running
instance itself (ie: Load event).

Signature

RobertK
{ Clever? No just smart. }

> I am producing a user control that partner sites will include in all their
> ASP.NET pages.  This control is responsible for logging important
[quoted text clipped - 41 lines]
> > > > RobertK
> > > > { Clever? No just smart. }

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.