Monday, March 26, 2012

trigger is causing the user controls OnInit to fire

I have a TextBox inside an UserControl which triggers an update panel on TextChanged. Works really well, but I noticed a problem. When AJAX makes the call back to the server to execute the TextChanged event, it is actually firing the UserControl's overridden OnInit beforehand. Is this normal behavior? I would think that for a page, OnInit should only get called once - when the page is created. There is a good deal of initialization code in my OnInit that really should not be executed again if it does not have to. Is there a way to make the UpdatePanel trigger not fire OnInit?

AJAX postbacks are executed at the server like normal postbacks (the entire page lifecycle is processed from the beginning), so Page.IsPostback = True for AJAX postbacks.

No comments:

Post a Comment