views:

805

answers:

4

Hi, I'm experiencing a very strange problem...

I have a regular ASP.Net webpage with a page_init and a page_load function. It is my understanding(from everywhere I look) that page_init gets called on the first page load(as in, not ever called in a postback) and page_load is called anytime something happens with the page.(It is very hard finding any info about this except for dead links and stuff about the page life cycle)

Well, I have an update panel containing other update panels and other assorted controls. Anytime I edit one of these controls, an async postback happens but instead of only page_load being called, page_init is also called which isn't suppose to happen(and didn't happen before a big codebase change)

So I would like to know anything that might cause this behavior or just if my idea of how page events are called is wrong.

A: 

My suggestion is that you create a simple example of what you're trying to do on a brand new scratch page based on these rules..

http://msdn.microsoft.com/en-us/library/ms178472.aspx

Keep adding complexity as you have it now until it breaks..

It would be difficult to diagnose your issue without the code..

madcolor
A: 

Page_Init is definitely called on every page hit, postback or not, exactly the same as Page_Load.

The misconception that Page_Init doesn't get called on every request seems to be a common one.

Are you certain that this wasn't happening before your "big codebase change"?

LukeH
I highly doubt it.. but maybe it could go unnoticed.. right now I'm having problems with stupid VS not showing me my events in the properties window so I can't actually change any events thanks to VS's brilliant code-hiding ability
Earlz
+1  A: 

I think you have the wrong idea of the page load life cycle. The OnInit event is called on EVERY request. Having the Page_Init method in your code behind is a shorthand way of wiring up the pages OnInit event.

Now I believe that you are confusing this with the "IsPostBack" property which will be set to true if a page posts back to itself i.e. when you click a Button etc. My guess is what you need to do is add an if statement in your Page_Init method i.e.

if(!IsPostBack){
//Do something to to update the UI
}
Owen
A: 

Your Page_Init as well as Page_Load both methods should be called each time.

Manoj